MATLAB Answers

0

how run .c program in matlab

Asked by manoj saini on 29 Jan 2013
Latest activity Commented on by Walter Roberson
on 26 Apr 2019
if i have program print.c
#include<stdio.h>
#include<conio.h>
main()
{
printf('hello')
getchar()
}
how i can run this code in MATLAB

  0 Comments

Sign in to comment.

2 Answers

Answer by Shashank Prasanna on 29 Jan 2013
 Accepted Answer

If you want to call your C function from within MATLAB you have to create a MEX file. Which mean you will have to modify your C code with the following guidelines:

  3 Comments

Or compile your C code in your favourite C programming environment into a dll/shared object and use loadlibrary to run it inside MATLAB.
rui gao
on 26 Apr 2019
How about now? I guess I can call C directly without the compiling. I am curious about it.
Walter Roberson
on 26 Apr 2019
It is not possible to call C or C++ directly from MATLAB without compiling the C or C++.

Sign in to comment.


Answer by syracus syr on 1 Feb 2018

@Shashank Prasanna I don't understand your explanation, how can I create this bat file. What should I put (code) in the file? For example, I have a "execute.bat" file. What should this file contain? Thank you so much!

  3 Comments

? I do not see any obvious reference to bat files in the links Shashank Prasanna posted?
Hi, @Walter Roberson, I want to call C function from within MATLAB with MEX file. I wrote here because I did not know the difference between MEX and BAT files. I've seen this title while researching c language with Matlab. Thank you!
mex files are DLL files with a different file extension, and which define a special function named mexFunction.
If you have an existing DLL then you can use loadlibrary() instead of building a mex interface to the C code.

Sign in to comment.