How to test for a vector/matrix of constants? [message #51776] |
Wed, 06 December 2006 10:21  |
Mirko
Messages: 20 Registered: April 1999
|
Junior Member |
|
|
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
|
|
|
Re: How to test for a vector/matrix of constants? [message #51835 is a reply to message #51776] |
Wed, 06 December 2006 20:58  |
mmeron
Messages: 44 Registered: October 2003
|
Member |
|
|
In article <1165429305.471782.64190@n67g2000cwd.googlegroups.com>, "Mirko" <mvukovic@nycap.rr.com> writes:
> 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?
>
Differences are quite fast enough since you can do it as vector
operation. Only, I wouldn't check for non-zero but for larger than
specified, user defined, "delta". So, you would do something along
the lines of
... if max(abs(vec[1:*] - vec)) gt delta then...
Mati Meron | "When you argue with a fool,
meron@cars.uchicago.edu | chances are he is doing just the same"
|
|
|