[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Easy about Matrices
From: |
Henry F. Mollet |
Subject: |
Re: Easy about Matrices |
Date: |
Mon, 18 Apr 2005 14:18:46 -0700 |
User-agent: |
Microsoft-Entourage/10.1.1.2418 |
I don't understand fully. As outlined x will end up to be a zero matrix,
whereas I thought one should end up with 2 matrices, pos values replaced
with zeros in one, negative values replaced with zeros in the other?
Henry
octave:18> x = randn(2,4)
x =
-0.273788 -0.671445 -1.522762 0.170152
-2.135687 1.040917 0.017514 -0.413427
octave:19> x_positive = x(x<0)=0
x_positive = 0
octave:20> x
x =
0.00000 0.00000 0.00000 0.17015
0.00000 1.04092 0.01751 0.00000
octave:21> x_negative = x(x>=0)=0
x_negative = 0
octave:22> x
x =
0 0 0 0
0 0 0 0
% Trying the following:
octave:27> x=xpos=xneg=randn(2,4)
x =
-0.77668 -0.21781 0.45580 -0.34135
-0.57917 0.78780 1.97339 -0.79024
octave:28> x_positive = xpos(xpos<0)=0
x_positive = 0
octave:29> xpos
xpos =
0.00000 0.00000 0.45580 0.00000
0.00000 0.78780 1.97339 0.00000
octave:30> x_negative = xneg(xneg>=0)=0
x_negative = 0
octave:31> xneg
xneg =
-0.77668 -0.21781 0.00000 -0.34135
-0.57917 0.00000 0.00000 -0.79024
octave:32> whos
*** local user variables:
prot type rows cols name
==== ==== ==== ==== ====
rwd matrix 2 4 x
rwd scalar 1 1 x_negative
rwd scalar 1 1 x_positive
rwd matrix 2 4 xneg
rwd matrix 2 4 xpos
on 4/18/05 11:06 AM, avraham at address@hidden 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
>
>
>
> -------------------------------------------------------------
> 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
> -------------------------------------------------------------
>
-------------------------------------------------------------
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
-------------------------------------------------------------
- Easy about Matrices, Alvaro Aguilera, 2005/04/18
- Re: Easy about Matrices, Mike Miller, 2005/04/18
- Re: Easy about Matrices, Peter Bodin, 2005/04/19
- Re: Easy about Matrices, Alvaro Aguilera, 2005/04/19
- Re: Easy about Matrices, Peter Bodin, 2005/04/19
- Re: Easy about Matrices, Mike Miller, 2005/04/19