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

조회 수: 2 (최근 30일)
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!!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by