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!