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
2017년 9월 25일
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
Joe Martinez
2017년 9월 25일
Star Strider
2017년 9월 25일
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.
카테고리
도움말 센터 및 File Exchange에서 Monte Carlo Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!