argument list of a function handel

2 ビュー (過去 30 日間)
Ruye Wang
Ruye Wang 2013 年 3 月 19 日
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!

採用された回答

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEntering Commands についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by