Basically I am trying to change the ticks on the y axis to be different but keep the same x axis ticks on both. I have looked online and through the textbook but was unable to get what I was looking for. I am attempting to label the top figure's y-axis as (-1,0,1,2), the bottom figure as (-0.2,0,0.2,0.4,0.6) and for both figures with an x-axis of (0,0.5,1,1.5,2)
x = linspace(0,2)
y1 = sin(2*pi*x);
y2 = exp(-0.5*2*pi*x).*sin(2*pi*x);
figure
subplot(2,1,1);
plot(x,y1,'rs')
subplot(2,1,2);
plot(x,y2,'k*')
Here is a way to do it. You need to change the YTick
and XTick
properties of the axes, as well as the YLim
property for the top plot, since by default Matlab tries to fit the axis with the range of data you have.
clear
clc
x = linspace(0,2);
y1 = sin(2*pi*x);
y2 = exp(-0.5*2*pi*x).*sin(2*pi*x);
figure
subplot(2,1,1);
hPlot1 = plot(x,y1,'rs');
%// The important part.
set(gca,'YLim',[-1 2],'YTick',-1:1:2,'XTick',0:.5:2)
subplot(2,1,2);
hPlot2 = plot(x,y2,'k*');
set(gca,'YTick',[-0.2,0,0.2,0.4,0.6],'XTick',0:.5:2)
Which looks like this: