How to graph 4 lines on one plot using a function?

조회 수: 1 (최근 30일)
Hunter Nau
Hunter Nau 2022년 4월 17일
답변: Chunru 2022년 4월 18일
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