Nested if statements done elsewise?

1 回表示 (過去 30 日間)
Konstantinos Belivanis
Konstantinos Belivanis 2015 年 9 月 26 日
回答済み: Rick Rosson 2015 年 9 月 26 日
Hello all,
I have a huge matrix of NNNNNNx8 elements. I would like to receive a vector with true or false, 1 or 0 values with the result of all 8 elements of each row to be simultaneously negative. That means a NNNNNNx1 matrix.
Of course I can do it with nested if statements and a loop for all rows but it slows down my program by a lot. If you can suggest any faster way of doing it?
Thanks in advance!

採用された回答

Rick Rosson
Rick Rosson 2015 年 9 月 26 日
N = 5000;
x = 2*rand(N,8) - 1;
u = (x<0);
v = (sum(u,2)==8);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by