MATLAB: How to get the row number of a row vector in a matrix

datamatrixrow

Now, master, I have some data, and they are continuous. Each have a coordinate (X, Y) and a row vector [a, b, c]. While, the row vector belongs to a matrix. I want to get the row number and make a new matrix [X, Y, i].
For example:
Here is a point(1,1) , it represents[3,4,5] , wile the matrix is
[1 1 2;
2 2 3;
3 3 4;
3 4 5;
6 6 7;
8 8 9]
So , the row number of it is 4. And save [1, 1, 4] into the new matrix.
Then, another point (1,2), it represents[8,8,9]. So It is the sixth line of the matrix. Add [1, 2, 6] to the new matrix.
Question: How can I determine which line the row is in?
How to save the data into the new matrix?

Best Answer

You can find the row with
A =[
1 1 2
2 2 3
3 3 4
3 4 5
6 6 7
8 8 9];
B = [8 8 9];
rowindex = find( ismember(A,B,'rows')>0);
Then you can extract that data from A and save it to another matrix.
For the two cases you present:
B = [3 4 5; 8 8 9];
point1 = [1 1];
point2 = [1 2];
rowindex = find( ismember(A,B,'rows')>0);
C = cat(1,point1,point2,rowindex');
In the matrix, C, the columns are the vectors you want.