help-octave
[Top][All Lists]
Advanced

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

Re: column elimination


From: Judd Storrs
Subject: Re: column elimination
Date: Mon, 19 Jul 2010 19:06:50 -0400

On Mon, Jul 19, 2010 at 6:48 PM, Victor Carreto Pavon
<address@hidden> wrote:
> yes... that is right; I want all the columns except 1 and 4 in this case,
> but maybe in the next case I might not want all the columns except 3 and 5.
> then the notation A(:,[2,3,5:cols]) will no longer be useful.
> Do you know can I make it generic so it will work for any combination?

I think you are asking for a generic way to eliminate columns using
only the column numbers you want to eliminate? I think the automatic
variable "end" and the setxor() function can get you that. So, for
example to remove columns 1 and 4 you could:

A = A(:,setxor(1:end,[1,4])) ;

and in the second case

A = A(:,setxor(1:end,[3,5])) ;

"end" is a special variable here that always equals the last index.
So, if A has 53 columns then 1:end is the same as 1:53--octave
automatically replaces end with the correct value so you don't need
the cols variable. setxor returns the numbers that are unique in the
two lists.


--judd


reply via email to

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