Which programming language is more useful

Dave

Joined Nov 17, 2003
6,969
I do believe there is a code generator for Matlab that will take your M-files or Simulink models and generate C code. Not that that is how I would go about writing C programs, but it is available.
Yes I have come across these before, however have never used them for any of my own work. You can also link directly to C-programs through MEX-files, this is one way around the interpreted limitation of Matlab.

To do this you need to create a MEX-file as:

Rich (BB code):
//Declare libraries
#include "math.h"
#include "mex.h"   // Must declare mex.h in order to link to Matlab

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
    //C-code
    
    return;
}
Then call the MEX-file from your M-file.

Dave
 

Dave

Joined Nov 17, 2003
6,969
That too. Though I was referring to Real Time Workshop which will generate C code from your M-files.
I didn't realise Mathworks had their own packages that did the conversion, thanks for the heads-up. I have seen toolboxes at universities for this, however as I said before I never tested them. I would be wary of using M-to-C convertor, particularly for vectorised mathematics constructs, but for rapid prototype development (which is where Real Time workshop seems to be focused) it certainly is a viable option.

Dave
 
Top