Help plotting a curve according to specific conditions of a variable

1 次查看(过去 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