Help plotting a curve according to specific conditions of a variable
조회 수: 3 (최근 30일)
이전 댓글 표시
I want my plot to display theta1's value as theta for all values of theta that range from 0 to pi and it should display theta1's value as (-theta) for all values of theta that range from pi to 2pi. This is my code so far. At this point, it's only plotting the value of theta1 from pi to 2pi as (-theta).
theta = linspace(0, 2*pi, 360);
theta1=[];
theta2= pi;
if (0<=theta)&(theta<=pi)
theta1=theta;
figure(1);
plot(rad2deg(theta), rad2deg(theta1));
hold on
elseif (pi<theta)&(theta<=2*pi)
theta1=-theta;
end
hold off
grid;
댓글 수: 0
채택된 답변
Alan Stevens
2020년 8월 25일
You mean like this?
theta = linspace(0, 2*pi, 360);
theta1=theta;
theta1(180:end) = -theta(180:end);
plot(rad2deg(theta), rad2deg(theta1)),grid
댓글 수: 1
Alan Stevens
2020년 8월 25일
Alternatively, if you don't want the vertical line:
theta = [0 180 NaN 180 360];
theta1 = [0 180 NaN -180 -360];
plot(theta,theta1), grid
is possible.
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!