1 view (last 30 days)

David Hill
on 9 Jan 2020

nnz(y<2);

David Hill
on 9 Jan 2020

I obviously don't understand, but if you have an array, y:

y=randi(10,1,100);

nnz(y<2)%gives you all values of y < 2 (this will not change unless y changes.

David Hill
on 9 Jan 2020

But each time you run the script,

z=nnz(y<2);

will provide you the number of values of y <2

Sign in to comment.

Meg Noah
on 9 Jan 2020

Here are random numbers as an example. It plots all the values in blue, finds indices for values less than 2, and plots those values in red.

x = 1:100;

y = 20*rand(100,1)-10;

ind = find(y < 2);

figure()

plot(x,y,'.b');

hold on

plot(x(ind),y(ind),'.r');

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 0 Comments

Sign in to comment.