How to write a code that counts how many numbers inside a vector is less than a specific vector?

So i have a randomily distrubited number as follows:
for i=1:1000
k(i)=unifrnd(1,20);
end
i want to write a code that checks how many numbers inside k are larger than 1, then how many larger than 2, then how many larger than 3 and so on until how many are larger than 19.
Thank you in advance.

Answers (1)

Try this —
k = unifrnd(1,20, 1, 1000);
for k1 = 1:19
Exceeds(k1,:) = nnz(k>k1);
end
Value = 1:19;
DesiredResult = table(Value(:),Exceeds)
DesiredResult = 19×2 table
Var1 Exceeds ____ _______ 1 1000 2 958 3 903 4 842 5 777 6 725 7 679 8 622 9 559 10 504 11 450 12 390 13 335 14 281 15 217 16 163
figure
plot(Value, Exceeds)
grid
.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Asked:

on 9 Nov 2021

Answered:

on 9 Nov 2021

Community Treasure Hunt

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

Start Hunting!