How to find some specific values of an array in another matrix ?

Hi, I have one <4X2> matrix that looks like x=[2 3 7 8 (Column1), 10 20 30 40(Column2)]. I have another <39X2> matrix that looks like y= [2:40 (column1), 39 specific values in column2]. I would like to find the column1 values of matrix x (2,3,7,8) in matrix y column1 (2:40) and then save the corresponding matrix y column2 values in a new matrix y1. For example: y1=[2 3 7 8, the corresponding specific values from the column2 of y matrix].
Special note: the values of matrix x=[2 3 7 8 (Column1), 10 20 30 40(Column2)] may change in different situations. So, it can also be x=[3 7 9 11, 30 50 70 90] at another time. But the matrix y is always fixed with same values.
Thank you so much for helping me out.

2 Comments

Your question is hard to read. Post an example without writing (column 1), we know it's column 1. And post what is the expected result.
Thanks for your comment. I have attached an illustration here. Does it help? :)

Sign in to comment.

 Accepted Answer

x=[ 2 10
3 20
7 30
8 40]
y= [2 0.2
3 0.3
4 0.2
5 0.2
6 0.2
7 0.5
8 0.6
9 0.2]
result_y1=y(ismember(y(:,1),x(:,1)),:)

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!