MATLAB Answers


How to use varargout function with matlab coder?

Asked by Jucimar Carpe on 20 Nov 2018
Latest activity Commented on by Jucimar Carpe on 21 Nov 2018
Hi, i'm trying to convert my Matlab script into C with Matlab Coder app but i'm having a problem, when app get into the "Check for Run-Time Issue" window it tells me: Top-level function cannot have varargout.
I'm not a programer so i have only basic knowledge. How can i procede to overcome this issue?


Sign in to comment.

1 Answer

Answer by Ryan Livingston on 20 Nov 2018
 Accepted Answer

Starting in MATLAB R2017b, MATLAB Coder supports varargout in entry-point functions. The documentation:
covers this in more detail.
In earlier releases, you can have a wrapper with explicit output arguments. So if you are trying to generate code for
function varargout = entryPoint(a,b,c)
you can instead use
function [out1,out2,out3] = entryPointWrapper(a,b,c)
[out1,out2,out3] = entryPoint(a,b,c);
and generate code from entryPointWrapper.


Hi Ryan, first of all, thank you for your help. I'm sorry but i didn't get it how do i should put in my code.
I'm currently using the Matlab 2015 version, so i will use the second option you gave me.
If i understood, the script you send me, i should use the second one you wrote. I'hva e many inputs and many outputs even 3 fugures. How should do it?
Attached is my currently script.
Yep, the second option, using a wrapper function without varargout, is the best way forward.
That said, looking at your script since there is a lot of plotting and graphics, MATLAB Coder isn't the best tool. As Kojiro Saito and Fred Smith and said in your other question:
MATLAB Compiler would be a better tool for your application because of the plotting/app code.
Hi Ryan, i already done by matlab compiler and created my GUI interface but the i was trying to codify do C, but it's ok. Thanks for the help!

Sign in to comment.