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;

채택된 답변

Alan Stevens
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
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개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by