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;
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!