help-octave
[Top][All Lists]
Advanced

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

Re: removing columns


From: nuncio m
Subject: Re: removing columns
Date: Tue, 3 May 2011 17:30:09 +0530

Hi Carne,
             My requirement is of the second kind.  HOwever 'sum' function wont do the job as my columns contain negative and positive values.  I just want to remove columns that are all zeroes.  I figured out another way using max and min functions
matrix = 0  -1   2
             0  -1   2
             0  -1   2
             0   1   2
             0   2   3


c_to_r=find(max(mat1)==min(mat1))
matrix(:,c_t_or)=[]

if 'sum' is used then 2nd column will also be removed

Here also there is one problem if the all elements are same but other than zero, then those columns will also be remove.  But at present I dont want those columns either.

Thanks
nuncio



2011/5/3 Carnë Draug <address@hidden>
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



--
Nuncio.M
Research Scientist
National Center for Antarctic and Ocean research
Head land Sada
Vasco da Gamma
Goa-403804

reply via email to

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