help-octave
[Top][All Lists]
Advanced

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

Re: Mask the matrix


From: Ben Abbott
Subject: Re: Mask the matrix
Date: Tue, 12 May 2009 10:53:14 -0400

 
On Tuesday, May 12, 2009, at 10:48AM, "James Sherman Jr." <address@hidden> 
wrote:

>On Tue, May 12, 2009 at 10:35 AM, Xin Dong <address@hidden> wrote:
>
>> Hi,
>>
>> I have a program that generates a two row matrix with zero elements. I
>> wanna extract out the columns with elements in both rows are non-zero. For
>> example, if the matrix is
>> a = [ 1 0 2 3 4; 2 1 0 0 4],
>> I wanna get
>> b = [1 4; 2 4].
>> How can I use octave to do this?
>>
>> Thanks,
>> Xin
>I'd so something like:
>
>c = all(a~=0,1);
>d = a([c;c]);
>b = reshape(d, 2, []);
>
>I think this will do what you want.
>

or ...

    b = a(:,min(a)!=0);

Ben



reply via email to

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