Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

optional input arguments for mex file

57 views
Skip to first unread message

Christian

unread,
Mar 4, 2014, 12:21:07 PM3/4/14
to
Hi,

I'm trying to create some mex files using the Coder tool in matlab. Is it possible to specify optional input arguments for those files?
Since the 'exist' command is not available for Coder I input optional arguments via [] in my original m-file. E.g.

function y=example(a,b,opt1,opt2)
'some code'
if isempty(opt1)==1
'perform some operations relying on code above'
end
'more code'
end

Then I call this function like this
z=example(a,b,[],[])

This approach is a bit clumsy, but thought it might work with mex files, but when I call the mex file using
z=example_mex(a,b,[],[])

I get an error saying that op1 is not of the correct size (which makes sense to me). Is there a clean way to deal with this, or do I have to set up sth like
z=example_mex(a,b,zeros(size(opt1)),zeros(size(opt2)))

and then change the if statement in the m-file to
if sum(opt1(:))==0

which probably takes up some computation time.

Steven Lord

unread,
Mar 5, 2014, 10:14:25 AM3/5/14
to

"Christian " <proe...@umich.edu> wrote in message
news:lf5223$3fe$1...@newscl01ah.mathworks.com...
Take a look at:

http://www.mathworks.com/help/coder/ug/rules-for-using-variable-length-argument-lists-for-code-generation.html

The NARGIN function may also be of use to you, and this page states it's
supported for code generation:

http://www.mathworks.com/help/coder/ug/functions-supported-for-code-generation--alphabetical-list.html

--
Steve Lord
sl...@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

0 new messages