How to get a script to only give me the number of elements less than 2?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Kyle Donk
am 9 Jan. 2020
Kommentiert: David Hill
am 9 Jan. 2020
I have a script in which y equals 100 various numbers. I was able to sort the numbers in order from least to greatest, but I need the script to give me the amount of numbers that are less than 2. How would I go about doing this?
0 Kommentare
Akzeptierte Antwort
David Hill
am 9 Jan. 2020
nnz(y<2);
4 Kommentare
David Hill
am 9 Jan. 2020
But each time you run the script,
z=nnz(y<2);
will provide you the number of values of y <2
Weitere Antworten (1)
Meg Noah
am 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');
2 Kommentare
Siehe auch
Kategorien
Mehr zu Descriptive Statistics 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!