How to find remaining row values from text file..?

I have this data1.txt file.
37.423588 18.871724 11.705919
37.426766 18.766546 11.701217
38.005723 18.134451 11.634655
39.041007 17.277316 11.527277
40.011146 15.164824 11.370832
40.007967 15.088475 11.367794
36.502911 20.190672 14.325146
35.914974 20.920768 16.896500
35.975486 20.946253 16.893447
36.062043 21.046045 16.891779
41.012003 13.878586 16.247513
40.987450 13.766184 16.244401
34.466285 23.481801 27.104811
And this is the data2.txt file.
37.283855 18.272258 11.689920
37.457463 18.622919 11.692993
38.008732 17.937276 11.626042
37.986514 17.777689 11.620758
39.772352 14.385744 11.353952
36.628875 20.010218 14.308833
36.634567 19.895388 14.303548
37.604998 20.055999 14.244000
41.275247 16.978169 13.861658
40.485970 15.036456 13.832871
Here in data1.txt file it contains first column with values 34,35,36,37,38,39,40 and 41.
No, data2.txt contains only 36,37,38,39,40 and 41 values in first column.
Now, i have to find remaining values rows like 34 and 35. so how to do it..?

2 Comments

Are you looking for exact matches, or are you wanting to round() the values or are you wanting to floor() them ?
Not, exact matches.? Only comparision of decimals before point. But answer should be whole row with points after decimal.
In this answer should be
35.914974 20.920768 16.896500
35.975486 20.946253 16.893447
34.466285 23.481801 27.104811

Sign in to comment.

 Accepted Answer

You can use ismember():
data1=[...
37.423588 18.871724 11.705919
37.426766 18.766546 11.701217
38.005723 18.134451 11.634655
39.041007 17.277316 11.527277
40.011146 15.164824 11.370832
40.007967 15.088475 11.367794
36.502911 20.190672 14.325146
35.914974 20.920768 16.896500
35.975486 20.946253 16.893447
36.062043 21.046045 16.891779
41.012003 13.878586 16.247513
40.987450 13.766184 16.244401
34.466285 23.481801 27.104811]
data2=[...
37.283855 18.272258 11.689920
37.457463 18.622919 11.692993
38.008732 17.937276 11.626042
37.986514 17.777689 11.620758
39.772352 14.385744 11.353952
36.628875 20.010218 14.308833
36.634567 19.895388 14.303548
37.604998 20.055999 14.244000
41.275247 16.978169 13.861658
40.485970 15.036456 13.832871]
col1data1 = unique(floor(data1(:,1)))
col1data2 = unique(floor(data2(:,1)))
contained = ismember(col1data1, col1data2)
intersect(col1data1, col1data2) % Just FYI
union(col1data1, col1data2) % Just FYI
notInData2 = col1data1(~contained)

11 Comments

The result is ok, but i want to find whole row values.. Not only first element.. and here in data1, 35 is two times, so it should find both rows of 35..
OK, you didn't say that at first. Do you know about the find() function? Try adding this code to the end of my script:
for k = 1 : length(notInData2)
lookingFor = notInData2(k)
rows = find(floor(data1(:,1)) == lookingFor)
end
OK, that's all until tomorrow...it's late here.
Or after "contained" is calculated,
notInData2 = data1(~contained,:);
It still shows only values 34 and 35 only, not whole row..
I tries using
[x,y,z] = find(notInData2(1,:,:) == data1(:,:,:))
But it shows an error..
It shows about comparision. I don't have to do comprision. I just have to find those rows of data1.txt whose first column element is not included in data2.txt.
The answer 34 qnd 35 is right, but now i have to find all those rows of data1.txt which contains 34 and 35 in its first column...
"==" is a comparison.
notInData2 = data1(~contained,:); should definitely show entire rows. Are you sure you were indexing data1() ?
In your line
[x,y,z] = find(notInData2(1,:,:) == data1(:,:,:))
why are you indexing data1 as if it were 3 dimensional? Why are you indexing notInData2() as if it were 3 dimensional?
col1data1 = unique(floor(data1(:,1)));
col1data2 = unique(floor(data2(:,1)));
contained = ismember(col1data1, col1data2);
intersect(col1data1, col1data2); % Just FYI
union(col1data1, col1data2); % Just FYI
notInData2 = col1data1(~contained,:);
notInData2 = data1(~contained,:);
This code shows first two rows of data1.txt as an answer.. So, what will be the modification to get desired answer..
col1data1 = floor(data1(:,1));
col1data2 = floor(data2(:,1));
contained = ismember(col1data1, col1data2);
notIndata2 = data(~contained, :);
It works.. Thank you .. How to accept this answer.?
There should be an "Accept This Answer" near Image Analyst's name on the Answer part itself.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!