0
votes

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

1 Answers

2
votes

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)