How can I select specific values using this loop?
Afficher commentaires plus anciens
So i want to use a loop to calculate the sine(in degrees) of specific intervals on a 360 degree scale
Here is what I have:
for x=0:60:360
s=sind(x)
end
What I want is to specifically use the for loop to calculate the sine of every value of x at 60 degree increments from 0 to 360 degrees. What could I do to correct my code?
Réponses (1)
Star Strider
le 25 Sep 2017
I would not use the loop, and instead use MATLAB’s ability to use vectorised commands:
x = linspace(0, 360, 7);
s = sind(x);
Result = [x; s]
Result =
0 60 120 180 240 300 360
0 0.86603 0.86603 0 -0.86603 -0.86603 0
2 commentaires
Joe Martinez
le 25 Sep 2017
Star Strider
le 25 Sep 2017
Another untagged homework Question!
Oh, well ... since I already started:
x = linspace(0, 360, 7);
for k1 = 1:length(x)
s(k1) = sind(x(k1));
end
Result = [x; s]
This produces the same ‘Result’ matrix as before, so I’ll not re-post it here.
Catégories
En savoir plus sur Monte Carlo Analysis dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!