How to graph 4 lines on one plot using a function?
1 次查看(过去 30 天)
显示 更早的评论
I have been working on graphing 4 lines on a graph based on there theta values. I can not get it to work with a function or plot the points, but there are no errors
^what it should look like
^what I have
%Test Inputs for theta in degrees
P1=angle(10)
P2=angle(30)
P3=angle(60)
P4=angle(95)
% function th=angle(th)
th=[10 30 60 95];
% i=1:length(th);
x=cosd(th);
y=sind(th);
figure(1)
% plot([P1-x P2-x P3-x P4-x],[P1-y P2-y P3-y P4-y])
hold on
plot(P1-x,P1-y,'m -o','linewidth',2),grid on %x position
hold on
plot(P2-x,P2-y,'k -o','linewidth',2),grid on %y position
hold on
plot(P3-x,P3-y,'b -o','linewidth',2),grid on %x position
hold on
plot(P4-x,P4-y,'r -o','linewidth',2),grid on %y position
legend('10 deg','30 deg','60 deg','95 deg','Interpreter','latex','fontsize',5)
hold off
xlabel('X Position (m)');
ylabel('Y Position (m)');
title('1DOF Planar Manipulator at different angular position')
xlim([-0.2 1])
ylim([0 1])
% end
0 个评论
采纳的回答
Chunru
2022-4-18
% function th=angle(th)
th = [10 30 60 95];
r = [0 1]'; % two points for each angle
% i=1:length(th);
x=r*cosd(th);
y=r*sind(th);
figure(1)
plot(x, y,'-o','linewidth',2);
legend('10 deg','30 deg','60 deg','95 deg','Interpreter','latex','fontsize',5)
hold off
xlabel('X Position (m)');
ylabel('Y Position (m)');
title('1DOF Planar Manipulator at different angular position')
xlim([-0.2 1])
ylim([0 1])
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Legend 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!