comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Comparing 2 arrays
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Comparing 2 arrays [message #55563 is a reply to message #55562] Sat, 25 August 2007 21:45 Go to previous messageGo to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
teich@atmsci.msrc.sunysb.edu writes:

> I would like to know if the data in two different 1 dimensional arrays
> are the same or not. This should be for every index. For example, if
> A=[0,1,2,3] and B=[0,1,3,2], then I would want the answer to be that A
> and B are not equal even though they happen to have the same values in
> different order. A problem with comparing each element is that the
> numbers are floating point so I would prefer not to compare with
> 'EQ'. Has anyone any suggestions?
>
> Alternatively, my arrays are actually from different structures. Is
> there a way to compare structures? For example, data1.A vs data2.B in
> the above example.


If your arrays are the same size, there is no problem using structures.
You could subtract the two values and call the result "equal" if
the difference was "sufficiently" close to zero.

IF Total( (data1.A - data2.B) LT 1e-6) EQ N_Elements(data1.A) THEN $
Print, 'The arrays are equal' ELSE Print, 'The arrays are unequal'

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Is there somebody familiar with nurbs or b-Spline?
Next Topic: File Output in IDL

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 13:46:10 PDT 2025

Total time taken to generate the page: 1.19656 seconds