How to plot with 3 matrix
4 ビュー (過去 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 で Scatter Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!