The issue is that logical indexing doesn't work when you are checking against a subset of the matrix:
>> A = [1 2 3 4; 2 0 1 5; 0 3 2 5; 1 2 1 0];
>> subsetOfRows = [1 2 4];
>> column = 2;
>> A(subsetOfRows,column)
ans =
2
0
2
>> A(subsetOfRows,column)>0
ans =
3×1 logical array
1
0
1
>> A(A(subsetOfRows,column)>0)
ans =
1
0
What's happening is that you extract the first, (not second), and third elements of A, instead of pulling out the full index from the subset. There may be some clever trick to do this in one step, but this will get it done in cases where the subset of A is not overly large
A = [1 2 3 4; 2 0 1 5; 0 3 2 5; 1 2 1 0];
subsetOfRows = [1 2 4];
column = 2;
tmp = A(subsetOfRows,column);
minimum = min(tmp(tmp>0));
Best Answer