Info

此问题已关闭。 请重新打开它进行编辑或回答。

how to reject whole columns based on a condition

1 次查看(过去 30 天)
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

回答(1 个)

Akira Agata
Akira Agata 2019-3-14
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);

此问题已关闭。

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by