Comments on: More Ways to Find Matching Data https://blogs.mathworks.com/loren/2009/01/20/more-ways-to-find-matching-data/?s_tid=feedtopost Loren Shure is interested in the design of the MATLAB language. She is an application engineer and writes here about MATLAB programming and related topics. Mon, 08 Jan 2018 20:19:51 +0000 hourly 1 https://wordpress.org/?v=6.2.2 By: Slart https://blogs.mathworks.com/loren/2009/01/20/more-ways-to-find-matching-data/#comment-32873 Tue, 03 Jan 2012 17:57:34 +0000 https://blogs.mathworks.com/loren/2009/01/20/more-ways-to-find-matching-data/#comment-32873 Ahh well there could be multiple matches for column 1 but then the column 2 would probably be different there should only be one match where both 1 and 2 match the same for both which would indicate an exact coordinate match. If that makes sense.

]]>
By: Loren Shure https://blogs.mathworks.com/loren/2009/01/20/more-ways-to-find-matching-data/#comment-32872 Tue, 03 Jan 2012 17:49:26 +0000 https://blogs.mathworks.com/loren/2009/01/20/more-ways-to-find-matching-data/#comment-32872 Slart-

Didn’t realize you were expecting possibly mulitple matches.

–Loren

]]>
By: Slart https://blogs.mathworks.com/loren/2009/01/20/more-ways-to-find-matching-data/#comment-32871 Tue, 03 Jan 2012 17:21:16 +0000 https://blogs.mathworks.com/loren/2009/01/20/more-ways-to-find-matching-data/#comment-32871 Hmm note sure how unique could help as I need every occurance not just he first and last. I really need to be able to find where in A the corresponding two values from B occur. I.E. matching both the first column and the second for an exact coordinate match.

Could you elaborate on how you think unique could help?

]]>
By: Loren Shure https://blogs.mathworks.com/loren/2009/01/20/more-ways-to-find-matching-data/#comment-32870 Tue, 03 Jan 2012 17:04:16 +0000 https://blogs.mathworks.com/loren/2009/01/20/more-ways-to-find-matching-data/#comment-32870 Slart-

Exact equality for floating point numbers is very iffy. You will need to build in a tolerance test.

Could you use unique looking for rows somehow with 3 outputs A and B?

–Loren

]]>
By: Slart https://blogs.mathworks.com/loren/2009/01/20/more-ways-to-find-matching-data/#comment-32869 Tue, 03 Jan 2012 16:52:07 +0000 https://blogs.mathworks.com/loren/2009/01/20/more-ways-to-find-matching-data/#comment-32869 Ok read thru this several times as it seems appropriate to my problem, however ismember does not take into account the duplicates and I need these to be true also.

I have A= 80,000×2 i.e.

[275.0919,-13.6656;275.1045,-13.8508…… ]

and B= 10,000×2 i.e.

[275.1045,-13.8508;…. ]

and need to find every occurance where the value in B occurs in A prefereable with the index for both included. My task is then to compare other values relating to these indexes in other arrays. These are actually coordinates and I need the ones that match in both, but there could always be a slight difference maybe the last decimal that would still need to be accepted. This sounds simple to do in my head and I am not a MATLAB expert by any means so any help in simple English would help. Thanks.

]]>
By: Loren https://blogs.mathworks.com/loren/2009/01/20/more-ways-to-find-matching-data/#comment-32536 Sat, 08 Oct 2011 16:21:43 +0000 https://blogs.mathworks.com/loren/2009/01/20/more-ways-to-find-matching-data/#comment-32536 Mahbub-

Welcome to the world of floating point arithmetic. The numbers you are printing out are not the full picture. If you use format long, you would likely see differences between the first 2 entities in your vector. == is only true if the numbers are non NaN, and are bitwise exactly equal. It’s much better to allow a tolerance when comparing floating point numbers. If you look through the blog for items with category numerical accuracy, you should see several relevant posts.

–Loren

]]>
By: Mahbub https://blogs.mathworks.com/loren/2009/01/20/more-ways-to-find-matching-data/#comment-32535 Sat, 08 Oct 2011 12:19:42 +0000 https://blogs.mathworks.com/loren/2009/01/20/more-ways-to-find-matching-data/#comment-32535 hi, I have an vector like x=[0.2000 0.2000 0.7375 1.0000 1.8125 2.0000 2.8875 3.0000 3.9625 4.0000 4.5000 4.5000]

unique does not stop repition of 0.2000 in this case.But in another similar case of 0.2000, it stops repetition.What is the solution

]]>
By: Loren https://blogs.mathworks.com/loren/2009/01/20/more-ways-to-find-matching-data/#comment-31921 Fri, 17 Dec 2010 12:17:46 +0000 https://blogs.mathworks.com/loren/2009/01/20/more-ways-to-find-matching-data/#comment-31921 Sudeera-

Why so complicated? You can just do


[row, col] = find(A==value)

no ismember needed…

–Loren

]]>
By: Sudeera Jayasekara https://blogs.mathworks.com/loren/2009/01/20/more-ways-to-find-matching-data/#comment-31920 Fri, 17 Dec 2010 07:16:58 +0000 https://blogs.mathworks.com/loren/2009/01/20/more-ways-to-find-matching-data/#comment-31920 The following code finds the specified value in A and gives its location,

A = [11 22 34 56 89
23 44 11 20 66
79 54 32 17 89
11 66 21 45 90];


value = 22; %value to be searched

[row,col]=find(ismember(A,[value]))
]]>
By: boris https://blogs.mathworks.com/loren/2009/01/20/more-ways-to-find-matching-data/#comment-31529 Fri, 23 Jul 2010 16:05:41 +0000 https://blogs.mathworks.com/loren/2009/01/20/more-ways-to-find-matching-data/#comment-31529 Great solution with ismember, thank’s Loren this is a wonderful time saver!
Boris

]]>