Re: How to test for a vector/matrix of constants? [message #51766 is a reply to message #51765] |
Wed, 06 December 2006 12:54   |
Paul Van Delst[1]
Messages: 1157 Registered: April 2002
|
Senior Member |
|
|
F�LDY Lajos wrote:
>
> On Wed, 6 Dec 2006, Mirko wrote:
>
>> How can I quickly check if a vector/matrix is full of constants (all
>> elements equal)?
>> For example if a vector contained:
>> [2.38,2.38,2.38,...,2.38]
>> I want it flagged as a "constant" vector.
>>
>> I can think of finding differences between successive elements, and
>> check for non-zero elements.
>>
>> Any faster options?
>>
>> Thanks,
>>
>> Mirko
>>
>
> my solution would be:
>
> mini=min(array, max=maxi)
> if mini eq maxi then ...
I think Bob's solution is the safest since that is the only one that doesn't use the "EQ"
operator. Insert the usual reasons here for not wanting to use "EQ" to compare floats.
cheers
paulv
p.s. Of course, one hopes the guts of ARRAY_EQUAL handles it correctly. :o)
--
Paul van Delst Ride lots.
CIMSS @ NOAA/NCEP/EMC Eddy Merckx
Ph: (301)763-8000 x7748
Fax:(301)763-8545
|
|
|