How to plot with 3 matrix
3 次查看(过去 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 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!