[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Zero entries in one column of a matrix
From: |
Henry F. Mollet |
Subject: |
Re: Zero entries in one column of a matrix |
Date: |
Thu, 01 Apr 2004 10:02:57 -0800 |
User-agent: |
Microsoft-Entourage/10.1.1.2418 |
Thanks for clear explanation.
Can I now also look at it as follows?
In M (: , 2) the ":" operator? says use all entries/rows in the second
column of M;
whereas in M (M(:,2) ~= 0 , 2), the implied ":" operator? looks at the
statement row by row and when it sees a boolean false (=0) says this is
*not* an index and therefore the entry (which was an actual 0) has to be
skipped?
Henry
on 3/31/04 11:54 PM, Miquel Cabanas at address@hidden wrote:
> hello,
>
> On Wed, Mar 31, 2004 at 10:40:05AM -0800, Henry F. Mollet wrote:
>>
>> But how does the elimination of the zero entries (in the second
>> column of M) work in M (statement, 1) producing col vector of
>> length 100-25=75, and M (same statement, 2) producing col vector
>> of length 75 also?
>
> because *statement* (i.e. "M(:,2) ~= 0" in your example) produces
> a boolean matrix, which is regarded as a matrix of indexes and
> handled by octave differently than standard matrices or vectors.
>
> octave:1> M = [ 1 1; 2 0; 3 1; 4 1; 5 0; 6 1; 7 1; 8 1; 9 0]
> octave:2> M_boolean = M(:,2) ~= 0;
> octave:3> whos
>
> *** local user variables:
>
> prot type rows cols name
> ==== ==== ==== ==== ====
> rwd matrix 9 2 M
> rwd bool matrix 9 1 M_boolean
>
> note though that as soon as you convert your bool-matrix into a
> plain-matrix this feature is gone,
>
> octave:4> M_plain = M_boolean .+ 0;
> octave:5> whos
>
> *** local user variables:
>
> prot type rows cols name
> ==== ==== ==== ==== ====
> rwd matrix 9 2 M
> rwd bool matrix 9 1 M_boolean
> rwd matrix 9 1 M_plain
>
> octave:6> M( M_plain , 1);
> error: invalid row index = 0
>
>
> Miquel
>
>
-------------------------------------------------------------
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
-------------------------------------------------------------