Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Is there any other ways instead of using for loop for this one?

1 回表示 (過去 30 日間)
SM
SM 2020 年 7 月 14 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
A={[10,11,10,7],[7,8,7,6],[11,10,9,9],[7,5,11,5];[9,8,6,11],[10,6,9,7],[6,12,8,9],[7,10,12,9];[10,7,12,6],[8,11,7,5],[8,5,9,9],[10,10,10,10]};
C=[1 1 0 1;0 1 1 1;1 0 1 1; 0 1 1 0];
[a,b]=find(~C);
for i=1:numel(a)
for j=1:size(A,1)
A{j,a(i)}(b(i))=100;
end
end
Is there any other smart ways to solve?

回答 (1 件)

Matt J
Matt J 2020 年 7 月 14 日
編集済み: Matt J 2020 年 7 月 14 日
It would be better if A were just a 3D numeric array,
Amat=cell2mat(reshape(A, size(A,1),1,[]))
Then you could simply do,
Amat(:,~C.')=100
  2 件のコメント
SM
SM 2020 年 7 月 16 日
Is it possible to get back from 3D numeric array to celll?
Matt J
Matt J 2020 年 7 月 17 日
Yes, use num2cell().

Community Treasure Hunt

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

Start Hunting!

Translated by