MATLAB: How to scale the length of the x-axis/graph

axisrescalingscaling

Hey,
I am plotting several 2D-profiles one after another with the same Matlab-script by just changing the input files. The x-axis displays the profile meter, e.g. goes from 0m to 100m and the y-axis the depth. I want to scale the x-axis in such way that 10m in both plots are the same (e.g. if you want so 1cm).
Is that possible? So I want to use the xlim for scaling, but how?
More info:
– I save the pictures as .eps if that makes a difference…
– Matlab 2015b
Edit: I added a picture

Best Answer

That property is governed by the Position property of the axis.
Here is an example:
figure
subplot(2,1,1), plot(100*rand(20,1),rand(20,1))
xlim([0 100])
set(gca,'Position',[0.1300 0.5838 0.7750 0.3412])
subplot(2,1,2), plot(50*rand(20,1),rand(20,1))
xlim([0 50])
set(gca,'Position',[0.1300 0.1100 0.7750/2 0.3412])
I don't manipulate this very often, so this may not be the best way.
Before setting those position, I first did
get(gca,'Position')
for each subplot, to see what the starting positions were. They were the vectors
[0.1300 0.5838 0.7750 0.3412]
for the top subplot, and
[0.1300 0.1100 0.7750 0.3412]
for the bottom subplot. These vectors are
[xstart ystart xwidth yheight]
Then, notice that I changed the xwidth of the bottom subplot, to half of the default. In your case, you'd want to manipulate that according to whatever you choose.
Here is the resulting figure: