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 CenterFile Exchange에서 Two y-axis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by