I have a matrix M that looks similar to 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'm trying to get a column vector with the rightmost non-zero value of each row in A, but ONLY for the rows that have the first column == 1.

I'm able to calculate a filter for the rows:

```
r = M( :, 1 ) == 1;
> r = [ 1; 1; 0; 0; 1 ]

```

And I have a set of indices for "the rightmost non-zero value of each row in M":

```
> c = [ 3, 2, 4, 3, 5 ]

```

How do I combine these in a slicing of A in order to get what I'm looking for? I'm looking for something like:

```
A( r, c )
> ans = [ 3; 2; 5 ]

```

But doing this gets me a 3x3 matrix, for some reason.