Select only some Index in matrix
4 views (last 30 days)
I have two variables:
whos var1 var2
var2 = [ 3 5 6 7 8 9 10 11 12 15 16]
I only want to keep this numbers as index in the third dimension of var1. It's correct If I just do the following?
var3 = var1(:,:,var2);
Or a better approach would be use a for loop?
for i1 = 1:size(var2,1)
dummy = var2(i1);
var3(:,:,i1) = var1(:,:,dummy);
I'm concerned with optimization since I need to do this inside another for loop. Which is better or is there another better approach?
Thank in advance