How can I select specific values using this loop?
Mostrar comentarios más antiguos
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?
Respuestas (1)
Star Strider
el 25 de Sept. de 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 comentarios
Joe Martinez
el 25 de Sept. de 2017
Star Strider
el 25 de Sept. de 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.
Categorías
Más información sobre Monte Carlo Analysis en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!