How to apply a cell array of function handles to an array of double

2 ビュー (過去 30 日間)
Artur Suglob
Artur Suglob 2019 年 5 月 15 日
コメント済み: Artur Suglob 2019 年 5 月 17 日
I've got code:
array_double = randi (3,3)
cell_array_fuction_handles ={@(x)x*2 @(x)x*4 @(x)x*6};
for k = 1:length (array_double)
array_double(k,:) = arrayfun (cell_array_fuction_handles{k}, array_double(k,:));
end
array_double
Is there any way to replace for-loop with a vector function?
Thanks!

採用された回答

Andrei Bobrov
Andrei Bobrov 2019 年 5 月 15 日
編集済み: Andrei Bobrov 2019 年 5 月 15 日
In your case:
out = array_double.*(2:2:6)';
General case:
out = arrayfun(@(x,y)cell_array_fuction_handles{x}(y),...
repmat((1:3)',1,3),array_double);
  4 件のコメント
madhan ravi
madhan ravi 2019 年 5 月 16 日
Well that is what I mentioned!!
Artur Suglob
Artur Suglob 2019 年 5 月 17 日
Thanks!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by