MATLAB: How to change the color of a plot with two y-axes on the same graph in Matlab

color

dear all
for the following program
how i can change the color of each plot
x = 0:0.01:20;
y1 = sin(x);
y2 = x;
figure % new figure
plotyy(x,y1,x,y2)
[hAx,hLine1,hLine2] = plotyy(x,y1,x,y2);
xlabel('Time (\musec)')
ylabel(hAx(1),'Slow Decay')
ylabel(hAx(2),'Fast Decay')

Best Answer

x = 0:0.01:20;
y1 = sin(x);
y2 = x;
figure % new figure

plotyy(x,y1,x,y2)
[hAx,hLine1,hLine2] = plotyy(x,y1,x,y2);
set(hAx(1),'ycolor','r'); % Change the color accordingly

set(hAx(2),'ycolor','c'); % Change the color accordingly
xlabel('Time (\musec)')
ylabel(hAx(1),'Slow Decay') ;
ylabel(hAx(2),'Fast Decay') ;
Or
x = 0:0.01:20;
y1 = sin(x);
y2 = x;
figure % new figure
plotyy(x,y1,x,y2)
[hAx,hLine1,hLine2] = plotyy(x,y1,x,y2);
set(hAx,{'ycolor'},{'r';'c'});
%..........x or y axex color, if x, use xcolor and change the colors accordingly
xlabel('Time (\musec)')
ylabel(hAx(1),'Slow Decay')
ylabel(hAx(2),'Fast Decay')