How to write a code that counts how many numbers inside a vector is less than a specific vector?
Show older comments
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)
figure
plot(Value, Exceeds)
grid
.
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!