Help plotting a curve according to specific conditions of a variable

1 view (last 30 days)
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;

Accepted Answer

Alan Stevens
Alan Stevens on 25 Aug 2020
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 Comment
Alan Stevens
Alan Stevens on 25 Aug 2020
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.

Sign in to comment.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!