-3

If I have a row

A =
     1     2     3     4     2     4     7

then I can delete twos with

>> A(A==2)=[]
A =
     1     3     4     4     7

Now suppose i have

>> A=[1,2,3,4,2,4,7; 1,2,3,4,5,6,7]
A =
     1     2     3     4     2     4     7
     1     2     3     4     5     6     7

then how to remove entire columns with twos at top?

Suzan Cioc
  • 29,281
  • 63
  • 213
  • 385

1 Answers1

3

Basic indexing:

A = [1,2,3,4,2,4,7; 1,2,3,4,5,6,7]
% Index those columns which have a 2 in first row
idx = A(1,:) == 2;
% Take all rows, but only column that do not have a 2 in first row
A   = A(:,~idx); % equivalent to A(:,idx) = [];
Oleg
  • 10,406
  • 3
  • 29
  • 57