help-octave
[Top][All Lists]

## Re: Easy about Matrices

 From: avraham Subject: Re: Easy about Matrices Date: Mon, 18 Apr 2005 21:06:59 +0300 User-agent: Mutt/1.5.5.1+cvs20040105i

```On Mon, Apr 18, 2005 at 12:43:05PM -0500, Quentin Spencer wrote:
> Alvaro Aguilera wrote:
>
> >Hello,
> >
> >I want to plot the data inside a matrix, but with different colors for
> >the negative and positve terms. I do this now by spliting the matrix
> >into two (negative, positive) using a "for" loop, and I wonder if
> >there is another better approach to do this.
> >
> >Any hint welcome :)
> >
> >Regards,
> > Alvaro.
> >
> I'm not completely sure if this is what you're looking for, but maybe
> this example helps:
>
> x = randn(1,1000);
> x_positive = x(find(x>=0));
> x_negative = x(find(x<0));
>
> -Quentin
>
>
>
> -------------------------------------------------------------
> Octave is freely available under the terms of the GNU GPL.
>
> Octave's home on the web:  http://www.octave.org
> How to fund new projects:  http://www.octave.org/funding.html
> Subscription information:  http://www.octave.org/archive.html
> -------------------------------------------------------------
Hi,
I do not really know if this is important for Alvaro Aguilera.
The drawback of your approach is that the relation between the
value and its place in the matrix is lost.
An alternative could be (example):
684~> x = randn(12,100);
x_positive = x(x<0)=0;
x_negative = x(x>=0)=0;
The two arrays have the size of the original one, but the terms
of "wrong sign" are replaced by zeros.
Check:
y=x_positive+x_negative;
694~> min(min(y-x))
ans = 0
694~> max(max(y-x))
ans = 0

In order to avoid plotting the points at y=0, one can use NaN
instead of 0: x_positive = x(x<0)=NaN; etc

Cheers, Avraham

-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------

```

reply via email to