help-octave
[Top][All Lists]
Advanced

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

Re: removing columns


From: Carnë Draug
Subject: Re: removing columns
Date: Tue, 3 May 2011 12:27:05 +0100

On 3 May 2011 12:00, nuncio m <address@hidden> wrote:
> Hi list,
>               I have a matrix of which all elements in some columns are
> zeroes.  Is there any trick to remove this columns
> and form a new matrix

Provided, you know which columns it's simple. The following code will
remove the columns 2 and 4

octave-3.2.4:7> matrix = eye(5)
matrix =

Diagonal Matrix

   1   0   0   0   0
   0   1   0   0   0
   0   0   1   0   0
   0   0   0   1   0
   0   0   0   0   1

octave-3.2.4:8> columns_to_remove = [2 4];
octave-3.2.4:9> matrix(:,columns_to_remove)=[]
matrix =

   1   0   0
   0   0   0
   0   1   0
   0   0   0
   0   0   1

If you don't know which columns only have zeros, you can use sum and
find to get the inedx of those columns.

> columns_to_remove = find(sum(matrix) == 0)

Carnë Draug


reply via email to

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