Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

return all columns except one matrix

Tags:

matrix

matlab

Suppose we have matrix A like this:

   10 5 8 6 2
A=  9 3 5 4 1
   12 5 7 2 6

How can I choose a subset of A where there is no third column(for example)??
like this:

    10 5 6 2
B =  9 3 4 1
    12 5 2 6

I know I can say:

B = A(:,[1 2 4 5]);

but I need a better way

like image 714
soroush gholamzadeh Avatar asked Dec 12 '22 02:12

soroush gholamzadeh


1 Answers

You can use

B = A(:,1:size(A,2)~=n);

with n as selected column (see answer of @freude).

His solution also works fine in any case, but locial indexing (as here) should be faster than his approach.

like image 83
Nemesis Avatar answered Dec 21 '22 21:12

Nemesis