figure size change but keep left bottom auto in matlab

You can use the axis function in MATLAB to set the axis limits of your plot. By default, if you change the limits of the plot, MATLAB will automatically scale the plot to fill the new size. However, you can set the 'preserve' option to maintain the aspect ratio of the plot.

Here is an example code snippet that demonstrates how you could implement this:

main.m
% generate some sample data
x = linspace(0, 2*pi, 100);
y = sin(x);

% plot the data
plot(x, y)

% set the x and y axis limits (the [xmin xmax ymin ymax] format is used)
axis([0 2*pi -1 1])

% preserve the aspect ratio
axis('preserve')
236 chars
13 lines

In this example, we generate some sample data, plot it using the plot function, and then use the axis function to set the x and y axis limits to be restricted between 0 and 2π for the x-axis and -1 and 1 for the y-axis. The 'preserve' option ensures that the aspect ratio is not distorted when the plot is scaled to fill the new size.

related categories

gistlibby LogSnag