C Code For Matlab Developers

April 22, 2011
The Mathworks now provides Matlab Coder to generate C and C++ code from Matlab applications. This code can be incorporated into C and C++ applications.

Matlab/C design flow

Mathworks has split its C and C++ code generation tools into three applications. They include Matlab Coder, Simulink Coder and Embedded Coder. These allow source code to be incorporated into C and C++ applications. Prior to this split, developers using Mathworks tools needed to turn to the Real Time Embedded tools to generate C or C++ code. Now Matlab and Simulink developers only need one additional tool to generate C and C++ code (Fig. 1).

The changes are significant because Matlab and Simulink are often used to develop or prototype applications that will be deployed using C or C++. Hand translation is one way to do this but it is tedious and error prone. It is also a pain to keep the C and C++ code in synch with the Matlab or Simulink code.

The three new tools eliminate a significant chunk of the work of maintaining a C/C++ application that utilizes algorithms developed using Matlab or Simulink. They essentially operate in the same fashion with slighly different starting points and they are complementary since Matlab code can be embedded in Simulink models. The embedded tool is essentially an updated version of the original C/C++ code generation support in the Real-Time Workshop Embedded Coder. It provides more advanced capabilities and requires Matlab Coder and/or Simulink Coder. It allows the user to adjust the look and feel of generated code including coding style as well as function library support. Embedded Coder provides a greater degree of control than Simulink and Matlab Coder at this time.

Matlab Coder features integration with Microsoft's Visual Studio. The tool makes it easy to find find Matlab code from the C/C++ code report.

The C/C++ tends to be 2x to 10x faster than corresponding Matlab code or Simulink models. The tools do not support all features in Matlab. Functional areas not supported include features like GUI interface support. The tools do support over 400 Matlab operators and funtions. In addition over 200 system objects like DSP algorithms are supported as well.

Addressing restricted functionality may mean refactoring a Matlab or Simulink application to move supported functionality into its own set of files. This can make debugging easier. The generated code is license and royalty free but resulting products cannot compete with Mathwords as is the case with regular Matlab applications.

Developers can select C or C++ code generation. The codegen command provides command line or make file support. Matlab Coder users will now only require a Matlab license to generate C/C++ code. The Realtime Workshop support still requires a Simulink license since it handles Matlab and Simulink code.

Pricing for Matlab Coder start at $6,500.

About the Author

William G. Wong | Senior Content Director - Electronic Design and Microwaves & RF

I am Editor of Electronic Design focusing on embedded, software, and systems. As Senior Content Director, I also manage Microwaves & RF and I work with a great team of editors to provide engineers, programmers, developers and technical managers with interesting and useful articles and videos on a regular basis. Check out our free newsletters to see the latest content.

You can send press releases for new products for possible coverage on the website. I am also interested in receiving contributed articles for publishing on our website. Use our template and send to me along with a signed release form. 

Check out my blog, AltEmbedded on Electronic Design, as well as his latest articles on this site that are listed below. 

You can visit my social media via these links:

I earned a Bachelor of Electrical Engineering at the Georgia Institute of Technology and a Masters in Computer Science from Rutgers University. I still do a bit of programming using everything from C and C++ to Rust and Ada/SPARK. I do a bit of PHP programming for Drupal websites. I have posted a few Drupal modules.  

I still get a hand on software and electronic hardware. Some of this can be found on our Kit Close-Up video series. You can also see me on many of our TechXchange Talk videos. I am interested in a range of projects from robotics to artificial intelligence. 

Sponsored Recommendations

Comments

To join the conversation, and become an exclusive member of Electronic Design, create an account today!