Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
optional input arguments for mex file

Subject: optional input arguments for mex file

From: Christian

Date: 4 Mar, 2014 17:21:07

Message: 1 of 2

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.

Subject: optional input arguments for mex file

From: Steven Lord

Date: 5 Mar, 2014 15:14:25

Message: 2 of 2


"Christian " <proechri@umich.edu> wrote in message
news:lf5223$3fe$1@newscl01ah.mathworks.com...
> 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.

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
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us