variables in c is input for a function running in matlab and print in c, how to
Show older comments
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
Walter Roberson
on 5 Jan 2022
Edited: James Tursa
on 5 Jan 2022
Rashi Mehrotra
on 6 Jan 2022
Edited: KSSV
on 6 Jan 2022
KSSV
on 6 Jan 2022
I think you may have to explore mex.
Rashi Mehrotra
on 6 Jan 2022
Walter Roberson
on 6 Jan 2022
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.
Rashi Mehrotra
on 6 Jan 2022
Walter Roberson
on 6 Jan 2022
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
Rashi Mehrotra
on 13 Jan 2022
Walter Roberson
on 13 Jan 2022
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?
Rashi Mehrotra
on 4 Feb 2022
Walter Roberson
on 4 Feb 2022
Edited: Walter Roberson
on 4 Feb 2022
Then use https://www.mathworks.com/help/matlab/matlab-api-for-c.html using functions such as engOpen() engPutVariable() engEvalString() engGetVariable()
Rashi Mehrotra
on 10 Feb 2022
Walter Roberson
on 10 Feb 2022
What error message do you observe?
Answers (1)
Benjamin Thompson
on 10 Feb 2022
0 votes
Use mex to build C code into a function callable in MATLAB. There is a lot of information and examples in the documentation.
Categories
Find more on Call MATLAB from C in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!