How to graph 4 lines on one plot using a function?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Chunru
le 18 Avr 2022
% 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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Legend dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!