MATLAB Answers

0

how to reject whole columns based on a condition

Asked by omar mahallawy on 14 Mar 2019
Latest activity Answered by Akira Agata
on 14 Mar 2019
A = [5 10 18 13
-2 8 -9 10
40 47 85 -30]
condiotion : remove columns with any negative numbers
result=[10
8
47]
kindly note that this is in a for loop

  0 Comments

Sign in to comment.

Tags

1 Answer

Answer by Akira Agata
on 14 Mar 2019

No need to use for-loop. Please try the following:
A = [5 10 18 13;
-2 8 -9 10;
40 47 85 -30];
idx = any(A<0);
result = A(:,~idx);

  0 Comments

Sign in to comment.