MATLAB Answers

Don S

running c program in matlab

Asked by Don S
on 26 Dec 2013
Latest activity Answered by Walter Roberson
on 27 Dec 2013


I have a general doubt. I have a c program and I would like to execute the program inside the matlab using unix command.For example if the .c file is "scale.c". Then if I give unix(scale);

it always show an error " not recognized as an internal or external command, operable program or batch file". Kindly provide a solution for this.


Do you want to start it as an independent program? or do you want to start it as an independent program except passing in stdin and out stdout? Or do you want to call various routines in the C source as if they are commands written in MATLAB, with access to the variables ?

Yes , I would like to call various routines in the C source into my matlab program.


No products are associated with this question.

4 Answers

Answer by Image Analyst
on 26 Dec 2013

Can you compile it into a standalone executable and run it with the system() function?


Answer by Walter Roberson
on 27 Dec 2013

To call routines in the C source, you have two choices:

  1. You can compile the C source as a library, and then loadlib() the library and call the routines; or
  2. You can create a MEX interface to the C source, compile it all with "mex", and then it can be called as if it is built-in MATLAB functionality.


Answer by The Matlab Spot on 26 Dec 2013

I dont know if you have referred s-functions

  1 Comment

are you trying to use the .c file in Simulink or a MATLAB program (script/function)?

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!