I nedd a hand with this

1 view (last 30 days)
Hi dear colleages... i`m fixing a script in matlab and i'm stucked in a really simple but confusing dilema.
Ok this is the problem:
I got two tables of different sizes, the first one "A" is composed by 3 columns, x, y and z, and 16 rows. THe second one "B" is formed by two columns, x and y and 6 rows.
The question is i need to obtain a final an output table fomed by 3 columns x,y,z composed by elements under the condition of:
1) element equals to the pair X,Y founded in table B, wich are present in table "A". 2) include also the third value Z (Table A) for items selected under the condition 1 3) Do not considers NaN present in both tables
Table A:
X Y Z 21 23 1 21 24 1 22 23 2 20 21 6 34 12 8 28 26 9 24 21 5 NaN NaN NaN 21 22 2 30 22 4 29 21 5 22 28 6 32 27 5 30 25 1 25 25 2 28 25 6 23 29 4
Table B
X Y Z 21 23 22 22 22 28 34 12 28 25 25 25
Requested answer:
21 23 1 22 28 6 34 12 8 28 25 6 25 25 2
thanx a lot... for any suggestion
PS: and if somebodie search for scripts for topographic analysis contact me

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 12 Oct 2011
out = A(ismember(A(:,1:2),B,'rows'),:)
OR
[lo1,loc] = ismember(A(:,1:2),B,'rows');
out = A(lo1,:);
[ignore,idx] = sort(loc(lo1));
out = out(idx,:);

More Answers (1)

Jules Ray
Jules Ray on 13 Oct 2011
you are the best andrei... thanx a lot

Products

Community Treasure Hunt

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

Start Hunting!