Nested if statements done elsewise?

1 Ansicht (letzte 30 Tage)
Konstantinos Belivanis
Konstantinos Belivanis am 26 Sep. 2015
Beantwortet: Rick Rosson am 26 Sep. 2015
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!

Akzeptierte Antwort

Rick Rosson
Rick Rosson am 26 Sep. 2015
N = 5000;
x = 2*rand(N,8) - 1;
u = (x<0);
v = (sum(u,2)==8);

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by