MATLAB: Sub2ind problem for matrix

sub2ind

I have a matrix
r =
6 1
5 2
4 3
3 3
2 3
1 2
2 3
3 3
4 3
5 2
6 1
and a matrix I.
I applied
idx=sub2ind(size(I),r)
It shows me the following:
idx =
6 1
5 2
4 3
3 3
2 3
1 2
2 3
3 3
4 3
5 2
6 1
how to get the correct one easily? thanks

Best Answer

idx=sub2ind(size(I),r(:,1),r(:,2))