variables in c is input for a function running in matlab and print in c, how to

How can I create a link between c and matlab, I have to take input from c program run a function in matlab and then print the output in c.

13 Comments

for example i have code in c
main()
{
int a,b;
a=5;
b=test(a);
printf("%d",b);
}
the function test() will run in Matlab and will display b in c.
Please tell
yes i can do with that but in my case input and output is from a single c code
WE use mex when we want to convert c code to matlab code, which i dont want to do, c code and matlab code run separetly and link together
MATLAB Compiler SDK perhaps, if there is a hard need to be able to call the function directly from C without having to write a shim to invoke the MATLAB Engine API.
can u please surely tell that if the sdk will do this?
No, I cannot tell you that. I have not used that product myself.
Question: is the intention that you would have a "live" (licensed, full featured) MATLAB session that you are interacting with from C? If so then you need Automation Engine or equivalent interface.
But if the intention is to build everything into an single executable that does not require a MATLAB licence to execute, then you either need MATLAB Compiler SDK or else MATLAB Coder
the requirement is as i have written to take input in c and function of matlab running giving output in c
Does this functionality have to be compiled into a single executable that needs to be able to run without a MATLAB license?
Or is it possible that it could run on a machine that had a licensed version of MATLAB installed and that the C program could ask the MATLAB program to do some work on its behalf?
yes it could run on a machine which has matlab installed and the function of c should run in matlab
Then use https://www.mathworks.com/help/matlab/matlab-api-for-c.html using functions such as engOpen() engPutVariable() engEvalString() engGetVariable()
There is engdemo.c in matlab API, whne i run it it gives me error.

Sign in to comment.

Answers (1)

Use mex to build C code into a function callable in MATLAB. There is a lot of information and examples in the documentation.

Products

Tags

Asked:

on 5 Jan 2022

Answered:

on 10 Feb 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!