How to apply a cell array of function handles to an array of double
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Artur Suglob
am 15 Mai 2019
Kommentiert: Artur Suglob
am 17 Mai 2019
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!
0 Kommentare
Akzeptierte Antwort
Andrei Bobrov
am 15 Mai 2019
Bearbeitet: Andrei Bobrov
am 15 Mai 2019
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!