|
From: | nuncio m |
Subject: | Re: removing columns |
Date: | Tue, 3 May 2011 17:30:09 +0530 |
On 3 May 2011 12:00, nuncio m <address@hidden> wrote:Provided, you know which columns it's simple. The following code will
> 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
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
[Prev in Thread] | Current Thread | [Next in Thread] |