Re: How to test for a vector/matrix of constants? [message #51765 is a reply to message #51764] |
Wed, 06 December 2006 12:58   |
Karl Schultz
Messages: 341 Registered: October 1999
|
Senior Member |
|
|
On Wed, 06 Dec 2006 20:59:45 +0100, =?ISO-8859-2?Q?F=D6LDY_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 ...
>
> regards,
> lajos
The ARRAY_EQUAL(a, a[0]) approach is probably the best, because it will
"short-circuit" or stop checking as soon as it finds an element that does
not match.
Karl
|
|
|