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!