How to get a script to only give me the number of elements less than 2?
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
David Hill
2020 年 1 月 9 日
nnz(y<2);
4 件のコメント
David Hill
2020 年 1 月 9 日
But each time you run the script,
z=nnz(y<2);
will provide you the number of values of y <2
その他の回答 (1 件)
Meg Noah
2020 年 1 月 9 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Descriptive Statistics についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!