How to plot with 3 matrix
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi everyone,
I used "plot" for drawing 2 two curve in one plot. I got it but one from these (red line) is not beautiful (the curve is not smooth) and I didn't understand why in area legend's didn't show green line. Anyone help me please. Below show the code I did. Thank you for advance.
clear all;
clc;
hold on
kr=[0 10 20 30 40 50 60 70 80 90];
M1=[0 0.2757 0.4979 0.4989 0.4481 0.3644 0.2910 0.2228 0.1380 0.0346];
M2=[0 0.0241 0.0916 0.1786 0.2613 0.3322 0.3895 0.4343 0.4658 0.4809];
plot(kr,M1,'x',0:90, interp1(kr,M1,[0:90],'spline'),'r','linewidth',1.5);
plot(kr,M2,'x',0:90, interp1(kr,M2,[0:90],'spline'),'g','linewidth',1.5);
grid on
xlabel('heel angel')
ylabel('arm')
legend('ld','ls','Location','northwest')
title('Diagram stability')
댓글 수: 0
채택된 답변
Star Strider
2020년 9월 27일
If you want the red and green lines to show, you need to plot them separately, and create handles for them to pass to the legend call:
hold on
kr=[0 10 20 30 40 50 60 70 80 90];
M1=[0 0.2757 0.4979 0.4989 0.4481 0.3644 0.2910 0.2228 0.1380 0.0346];
M2=[0 0.0241 0.0916 0.1786 0.2613 0.3322 0.3895 0.4343 0.4658 0.4809];
plot(kr,M1,'x')
hp1 = plot(0:90, interp1(kr,M1,[0:90],'spline'),'r','linewidth',1.5);
plot(kr,M2,'x')
hp2 = plot(0:90, interp1(kr,M2,[0:90],'spline'),'g','linewidth',1.5);
grid on
xlabel('heel angel')
ylabel('arm')
legend([hp1 hp2], 'ld','ls','Location','northwest')
title('Diagram stability')
.
댓글 수: 2
Star Strider
2020년 9월 28일
My pleasure!
It looks very smooth to me already. I do not know what ‘more smooth’ means to you, so I defer to you to experiment with it. One option is to use 'pchip' (my usual preference) or 'makima' rather than 'spline'. The 'makima' method appears to me to work best here, however that is your decision.
If my Answer helped you solve your problem, please Accept it!
.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!