Filter löschen
Filter löschen

argument list of a function handel

3 Ansichten (letzte 30 Tage)
Ruye Wang
Ruye Wang am 19 Mär. 2013
I can pass the elements of a list to a function handle:
>> f=@(x,y)x+y
>> f(1,2)
ans = 3
>> x=[1 2]
>> f(x(1),x(2))
ans = 3
But how can I pass the list to the function handle instead of explicitly specifying each element of it? I tried the following but neither worked:
>> f(x)
??? Input argument "y" is undefined.
>> f(x(:))
??? Input argument "y" is undefined.
Thanks for help!

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 19 Mär. 2013
xcell = num2cell(x);
f(xcell{:});
Note that if you are not using scalars, the approach would need to be modified.

Weitere Antworten (0)

Kategorien

Mehr zu Get Started with Aerospace Blockset finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by