Using hold all with plotyy

2 ビュー (過去 30 日間)
Si
Si 2015 年 1 月 30 日
回答済み: Si 2015 年 2 月 3 日
When I use hold all with plot, all the colors of the lines in the figure can be different automaticly, but when I use it with plotyy , it does not work that well, as there are two handles to hold. So how can I fix it? Thanks. My code is as follows,
x1 = 0:0.01:10;
x2 = 0:1:10;
y1 = sin(x1);
y2 = sin(x2);
y3 = 10*cos(x1/2);
y4 = 10*cos(x2/2);
y5 = x2;
figure
[hAx,hL1,hL2] = plotyy(x1,y1,x2,y2);
set(hAx(1),'YLimMode','auto');
set(hAx(2),'YLimMode','auto');
set(hAx(1),'YTickMode','auto');
set(hAx(2),'YTickMode','auto');
hold(hAx(1),'all');%hold all
hold(hAx(2),'all') ;
plot(hAx(1),x2,y4);
plot(hAx(1),x1,y3);
plot(hAx(2),x2,y5);
hold(hAx(1),'off');%hold off
hold(hAx(2),'off') ;

回答 (1 件)

Si
Si 2015 年 2 月 3 日
Well, I will answer it myself, 1. Do not use hold; 2. Put all the lines together;
So the final code will be something like,
hAx=plotyy([x1;x2;x3;....;xn],[y1;y2;y3;...;yn],[xa;xb;xc;...;xz],[ya;yb;yc;...;yz]);
x1~xn and y1~yn should have the same length; xa~xz and ya~yz should have the same length;
If the length is differnt, use interpolation to make them with the same length.

カテゴリ

Help Center および File ExchangeTwo y-axis についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by