How to select odd numbers in a row
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
JGraf
le 20 Fév 2017
Réponse apportée : Image Analyst
le 20 Fév 2017
Hi, I need to write a function that returns an output, which is the square root of the mean of the squares of the first nn positive odd integers. nn is a positive integer and is the only input argument. If nn is 3, my function needs to compute and return the square root of the average of the numbers 1, 9, and 25. (Because 1, 3 and 5 are the first 3 odd integers)
So far I have:
function orms = odd_rms(nn)
h=[1:nn]
h=h.*h
orms=(sum(h(:)))
orms=sqrt(orms/nn)
end
However, I am not sure how to select the odd numbers only. I tried using mod, but that didn't work. Maybe I used it wrong. I am also not supposed to use the built-in function rms.
Thanks a lot!!!
0 commentaires
Réponse acceptée
Image Analyst
le 20 Fév 2017
You computed "h" incorrectly. The correct equation is:
h = 1 : 2 : nn*2
0 commentaires
Plus de réponses (1)
Star Strider
le 20 Fév 2017
Consider the definition of an odd number, and go from there. The rem or mod functions could be helpful.
0 commentaires
Voir également
Catégories
En savoir plus sur Data Distribution Plots 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!