1 view (last 30 days)

Show older comments

David Hill
on 9 Jan 2020

nnz(y<2);

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

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');

Meg Noah
on 9 Jan 2020

to display on the console, just use num2str or fprintf

num2str(numel(ind))

fprintf(1,'There are %d values less than 2\n',numel(ind))

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

Start Hunting!