a problem with conditions and deleting rows

1 view (last 30 days)
dear all, this is maybe a simple question but i can not find the way to solve it... may be you can help me...
i got a 1x4 (double) matrix named codename_station
codename_station=
77 79 90 79
i have also a big matrix named tab, composed by 6 columns and many rows, tab is also double
tab=
67 66 81 67 95.5400000000000 0.630000000000000
80 85 72 69 31.9400000000000 0.990000000000000
77 79 90 79 230.930000000000 2.59000000000000
80 73 67 72 6.09000000000000 1.90000000000000
84 69 84 65 12.1700000000000 0.570000000000000
84 69 84 65 60.3900000000000 0.520000000000000
67 79 78 84 438.610000000000 0.970000000000000
77 79 90 79 74.6700000000000 1.02000000000000
as you see the first four columns represent the coded name (double('string')), where the string is composed by four letters like CBQC or CONT etc....
how ever, i need to create a code to create a new table only with the rows the table tab, that coincide with the codename_station columns....
i mean, i need a new table called tab2 (for example) with this data
tab2=
77 79 90 79 230.930000000000 2.59000000000000
77 79 90 79 74.6700000000000 1.02000000000000
as you see the first four rows concede with the four rows of codename_station
i have been trying with this code:
if tab(:,(1:4))~=codename_station(1,(1:4));
tab(:,:)=[];
end
but gives me an error that says
Error using ~=
Matrix dimensions must agree.

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 4 May 2012
out = tab(ismember(tab(:,1:4),codename_station,'rows'),:)

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!