sub2ind with 3D matrix?

13 views (last 30 days)
MementoMori
MementoMori on 4 Apr 2023
Edited: DGM on 4 Apr 2023
given a code, for example, like this
A=rand(10,10);
indX(:,:,1)=[2,3;1,6]; indX(:,:,2)=[2,5;2,6];
indY(:,:,1)=[4,6;2,3]; indY(:,:,2)=[7,5;3,4];
for i=1:2
for j=1:2
ind=sub2ind(size(A), indX(:,:,i), indY(:,:,j));
figure,imagesc(A(ind));
end
end
I would like to obtain the same result, without using a for loop. Is there any faster way?
  2 Comments
DGM
DGM on 4 Apr 2023
Edited: DGM on 4 Apr 2023
The faster way would be to not generate a bunch of figures in a loop. If you don't need them, don't spend time on them. If you might need them, conditionally generate them only when requested.

Sign in to comment.

Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!