Write a random row vector x of size 1x10000. Find out the number of the elements of x that are below 0.2. Use a for loop for this.
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
kerem yaman
le 3 Avr 2022
Commenté : kerem yaman
le 3 Avr 2022
Can you help me? I wanted to solve this problem but I faced an error.
Write a random row vector x of size 1x10000. Find out the number of the elements of x that are below 0.2. Use a for loop for this.
-------
% generate a random row vector x of size 1x10000 and the number of the elements of x that are below 0.2
% assign x with 10000 random numbers
x = rand(10000,1);
% assign count with 0
count = 0;
% loop runs for 1 to 10000
% check the number is less than 0.2
% increment count by 1
for i = 1:10000
if(x(i) < 0.2)
count = count + 1;
end
end
count
----------
Error using count
Not enough input arguments.
0 commentaires
Réponse acceptée
Image Analyst
le 3 Avr 2022
Your code works. You probably made that script called count.m or else you have another m-file in the folder, or on the search path, that is called count.m. Either rename your variable to theCount or rename your m-file to something else.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!