Reputation: 414
I have a matrix in matlab as follows:
1 1 1
2 2 1
3 3 0.075
12 3 0.025
4 4 1
5 5 1
6 6 1
I'm trying to find the value of the third column, given that the VALUE not the index of the first 2 columns are lets say: 12,3. Then it should output 0.025. I've tried using ismember and find function, but i can't figure out how to solve the issue in MATLAB.
Upvotes: 4
Views: 1228
Reputation: 9317
ismember
works fine here if you (1) only feed the first two columns of A
into the function and (2) use the 'rows' option with this function:
A = [1 1 1
2 2 1
3 3 0.075
12 3 0.025
4 4 1
5 5 1
6 6 1]
idx = ismember(A(:,1:2), [12 3], 'rows'); % find index of valid row
A(idx, 3) % query third column of valid row
This results in
ans =
0.0250
Upvotes: 5