Arrayfun with multiple variable?
47 ビュー (過去 30 日間)
古いコメントを表示
Hi, probably this question has already received answers but what I found don't solve my problem.
I know that I have a function that requires one input i can use arrayfun like this:
A=arrayfun(@functionExample, input1);
But if I have a function that requires more than one input how can I do?
Thanks
0 件のコメント
回答 (2 件)
Voss
2022 年 4 月 19 日
Two inputs:
A=arrayfun(@(x,y)functionExample(x,y), input1, input2);
Three inputs:
A=arrayfun(@(x,y,z)functionExample(x,y,z), input1, input2, input3);
And so on.
3 件のコメント
Stephen23
2022 年 4 月 19 日
It is not required to use anonymous functions, a simple function handle works with any number of inputs:
V = arrayfun(@max,[1,2,3],[0,9,0])
Stephen23
2022 年 4 月 19 日
編集済み: Stephen23
2022 年 4 月 19 日
"But if I have a function that requires more than one input how can I do?"
ARRAYFUN already works with any number of input arrays:
fnh = @(varargin)sum([varargin{:}]); % test function, any number of inputs
arrayfun(fnh,[1,2,3])
arrayfun(fnh,[1,2,3],[4,5,6])
arrayfun(fnh,[1,2,3],[4,5,6],[7,8,9])
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で GPU Computing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!