Mahdi
Mahdi

Reputation: 1827

Find a Specific row based on value of a column in a matrix

I have a matrix with following structure

X    Y    ID
1    2    10
15   20    2

I want to find the index of row based on ID column. please advice me.

Upvotes: 0

Views: 741

Answers (1)

p8me
p8me

Reputation: 1860

Use find:

ind = find(M(:,3) == id)

You could add 'first' or 'last' like find(M(:,3) > id, 'first').

Upvotes: 3

Related Questions