I have a matrix M that looks something like this:
M = [ 1, 2, 3, 0, 0; 1, 2, 0, 0, 0; 2, 3, 4, 5, 0; 4, 5, 6, 0, 0; 1, 2, 3, 4, 5; ]
I am trying to get a column vector with the smallest nonzero value of each row in A, but ONLY for rows that have the first column == 1.
I can calculate filter for strings:
r = M( :, 1 ) == 1; > r = [ 1; 1; 0; 0; 1 ]
And I have a set of indices for the "rightmost nonzero value of each row in M":
> c = [ 3, 2, 4, 3, 5 ]
How to combine them in section A to get what I'm looking for? I am looking for something like:
A( r, c ) > ans = [ 3; 2; 5 ]
But for some reason I get a 3x3 matrix.