[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 13:53:04 +0100 |
2011/5/3 nuncio m <address@hidden>:
> 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.
Then to remove all columns that have all zeros, taking into account
that columns can have the same element on all rows, and negative and
positive values who sum is zero, here's what you can do
index_of_equal = find(max(matrix) == min(matrix));
columns_to_remove = index_of_equal(find(matrix(1,index_of_equal)==0));
I apologize if it doesn't make much sense or there's an error but I've
only had 5h of sleep on the last 3 days.
Carnë Draug