Programming: keep theta between specific values
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi every one,
I have a problem in programming. I have theta which start from 0 and goes to unspecified value. I want to reset theta if it reached to 2pi and keep it always between [0,2pi]. I wrote a code but it is not true for all situation(Ex after 4pi). My code is:
if theta>2*pi
theta=theta-2*pi;
end
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/145192/image.jpeg)
댓글 수: 0
답변 (2개)
Star Strider
2014년 8월 26일
편집: Star Strider
2014년 8월 26일
You can do that with the rem function:
x = linspace(0,10*pi);
theta = rem(x, 2*pi);
figure(1)
plot(x/pi,theta/pi)
grid
xlabel('Angle (x \pi)')
ylabel('Angle (x \pi)')
They are plotted as multiples of pi for convenience in visualising the result.
댓글 수: 2
Star Strider
2014년 8월 26일
A (1x1) matrix is a scalar.
My code does exactly what you illustrated. It produces vectors of values from (0,2*pi) from your linearly increasing vector that goes from zero to at least 6*pi.
Babak
2014년 8월 26일
댓글 수: 1
Star Strider
2014년 8월 26일
Run your code and see if it produces the result you illustrated.
Mine does.
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Object Properties에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!