[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Mask the matrix
From: |
Jaroslav Hajek |
Subject: |
Re: Mask the matrix |
Date: |
Wed, 13 May 2009 16:17:58 +0200 |
On Tue, May 12, 2009 at 4:59 PM, Przemek Klosowski
<address@hidden> wrote:
> You can do it this way: a(:,!sum(a==0))
>
> Explanation:
>
> - a==0 is a matrix with '1' where your data has zeros
> - sum(a==0) adds them up columnwise, so it will be zero only if no zeros
> were in that column.
> - a(:,!sum(a==0)) selects full columns based on a boolean mask created from
> the prev. expression
a slightly better expression is
a(:, all (a)).
because, in general, `all' and `any' are faster than `sum', because
they use short-circuiting.
--
RNDr. Jaroslav Hajek
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz