0

I need pass to a function (jacobian() in my case) a symbolic variable array is being creating dynamically. Say,

jacobian(handles{2}(t,y,paramlist),y)

where paramlist=[var1, var2, var3, ..., varN] has an arbitry size. All variables here are symbolic and have various names. MATLAB throw an error:

Not enough input arguments.

Knowing number of parameters in the function definition one can pass all parameters separately. Say, for n=3:

 jacobian(handles{2}(t,y,paramlist(1),paramlist(2),paramlist(3)),y)

But what about the common case? It's a bad style of programming to write the function call for each fixed number of parameters. Is there a way to pass an array so as it would be treated as distinct variables?

1 Answer 1

2

You can convert paramlist to a cell array (using num2cell) and then use {:} indexing to create a comma separated list which you can then use this for indexing into handles{2}. This will make it such that each value of paramlist is passed as a separate subscript.

plistcell = num2cell(paramlist);
jacobian(handles{2}(t, y, plistcell{:}), y)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.