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?

답변 (1개)

Star Strider
Star Strider 2017년 9월 25일

0 개 추천

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

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.

댓글을 달려면 로그인하십시오.

카테고리

질문:

2017년 9월 25일

편집:

2017년 9월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by