How can I select specific values using this loop?

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
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
Joe Martinez el 25 de Sept. de 2017
Definitely need to execute it as a loop for an assignment. This is part of a larger problem, but I need to start with doing this first step as a loop
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.

Iniciar sesión para comentar.

Preguntada:

el 25 de Sept. de 2017

Editada:

el 25 de Sept. de 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by