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

采纳的回答

Chunru
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 个)

类别

Help CenterFile Exchange 中查找有关 Legend 的更多信息

标签

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by