4
votes

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.

1
could you be a bit more specific? have you tried with A(18)?fpe

1 Answers

5
votes

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