Create a linear index with sub2ind, and use it to get the elements you want:
M = randi(99, 3, 2) % Create Matrix linidx = sub2ind(size(M), 1:size(M,1), [1 2 1]) % Linear Index Out = M(linidx)
M = 95 15 49 42 80 91
Out = 95 42 80
Create a linear index with sub2ind, and use it to get the elements you want:
M = randi(99, 3, 2) % Create Matrix linidx = sub2ind(size(M), 1:size(M,1), [1 2 1]) % Linear Index Out = M(linidx)
M = 95 15 49 42 80 91
Out = 95 42 80
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!