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!