Reputation: 335
Say I have a matrix
A = [1, 2, 3; 4 5 6; 7 8 9]
If I want to choose say (1,2), (2,3)
I could not say A(1:2,2:3) otherwise it will return a 2*2 matrix, what should I do it for only one time...
Upvotes: 2
Views: 588
Reputation: 221574
Use sub2ind to linearly index (to avoid creating a matrix) using the given row and column numbers -
sub2ind
ind = [1,2;2,3] A(sub2ind(size(A),ind(:,1),ind(:,2)))
Upvotes: 4