change figure size in matlab

To change the size of a figure in Matlab, you can use the set command to modify the 'Position' property of a figure.

Here's an example code snippet:

main.m
% Create a simple plot
x = 1:10;
y = sin(x);
plot(x,y);

% Get the handle to the current figure
fig = gcf;

% Change the figure size
fig.Position(3:4) = [800 500];
164 chars
11 lines

In this example, gcf returns a handle to the current figure. Then, we change the 'Position' property to set the figure size to 800 pixels wide by 500 pixels tall (the first two elements of the 4-element 'Position' vector). You can adjust these values to the desired figure size.

Alternatively, you can also set the figure size when you create the figure using the 'Position' name-value pair argument. For example:

main.m
figure('Position',[100 100 800 500]); % left, bottom, width, height
68 chars
2 lines

This will create a new figure with a size of 800 pixels wide by 500 pixels tall, positioned at 100 pixels from the left edge of the screen and 100 pixels from the bottom.

related categories

gistlibby LogSnag