×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Matlab - Compare 2 array values

Matlab - Compare 2 array values

Matlab - Compare 2 array values

(OP)
I have two arrays holding coordinates of the cell centers for a finite volume program. One array has 100 x and y values whilst the other has 16 values. I would like to match the cell centers that have the same x and y coordinates in the 2 arrays. Currently I am able to do this using for loops but it takes forever to run through the values for larger arrays.
Can anyoe give advice on how this process can be simplified using matlabs built in matrix functions?
I eagerly await any suggestions.

RE: Matlab - Compare 2 array values

CODE

% assuming that your arrays are in the form
% A = x1   y1   and  B = X1   Y1
%     x2   y2            X2   Y2
%     :    :             :    :
%     x100 y100          x16  y16
%
% i.e. rows of x-y pairs (not necessarily 100 or 16 rows)

% Generate a test matrix of the form A above

A = rand(100,2)

% Generate a test matrix of the form B above
% (some of whose members are the same as A)

B = [   A([1 16 29 43 32],:)
        1.2 3.4
        55.4 60.3
        A([12 3 4 99 84],:)
        34.5 56.7
        A([66 78 36],:)    ];

% find the set-wise intersection between the two datasets
% and the corresponding indices

[C, A_idx, B_idx] = intersect(A, B, 'rows');

% C contains the matching x-y pairs
% A_idx contains the row numbers of A corresponding to the
% matching pairs
% B_idx contains the row numbers of B corresponding to the
% matching pairs
% such that C == A(A_idx, :) == B(B_idx, :)

[C, A(A_idx,:), B(B_idx,:)]
M

--
Dr Michael F Platten

RE: Matlab - Compare 2 array values

(OP)
Thanks alot Mickey...I used it and it works wonderfully...

RE: Matlab - Compare 2 array values

Hot damn...  That is pretty good.  I've had the same problem in the past.  Thanks for the info!  

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Resources

Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Design for Additive Manufacturing (DfAM)
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a part’s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now