How can I avoid using FOR loops and the FIND command for multidimensional array indexing?
古いコメントを表示
I would like to manipulate elements of multidimensional arrays. When working with large arrays, both using FOR loops and avoiding FOR loops by using the FIND function are computationally slow.
As an example, consider the following:
Suppose A is a 10x10x10 matrix as follows:
A=rand(10,10,10);
A(1,2,2)=2;
A(3,4,1)=2;
A(5,6,3)=2;
I would like to set the array elements whose value is 2 to zero. I avoid using FOR loops and use instead the FIND and IND2SUB commands:
I=find(A==2);
[u,v,w]=ind2sub(size(A),I);
A(u,v,w)=0;
For large data arrays, however, this method is computationally slow.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!