help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Easy about Matrices


From: Quentin Spencer
Subject: Re: Easy about Matrices
Date: Mon, 18 Apr 2005 13:26:28 -0500
User-agent: Mozilla Thunderbird 1.0.2-1.3.2 (X11/20050324)

avraham wrote:

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

That's a valid point. That would be the correct approach for generating a line plot.

In my approach I was envisioning a scatter plot without lines where both the x and y values were split, i.e. converting "plot (x,y,'.')" into "plot(x_positive,y_positive,"1."); plot(x_negative,y_negative,"2.");".

-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
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]