figure
Creates a new figure for plotting and uicontrols.
Syntax
h = figure()
h = figure(n)
Inputs
- n
- Type: integer
Outputs
- h
- Handle of the figure.
Examples
figure (2)
function onCreate(handle, data)
data; % data is not used
disp(['Figure ', num2str(handle), ' is created'])
end
function onDelete(handle, data)
data; % data is not used
disp(['Figure ', num2str(handle), ' is deleted'])
end
figure('createfcn', 'onCreate', 'deletefcn','onDelete');
disp('Pausing for 1 sec...')
pause(1)
disp('Deleting figure')
close(gcf)
function onSizeChanged(handle, data)
data; % data is not used
disp(['Figure ', num2str(handle), ' is resized'])
end
figure('sizechangedfcn','onSizeChanged');
% use the mouse to resize the figure and check the function output in the console
function onKeyPress(handle, data)
data
disp(['Figure ', num2str(handle), ' Key pressed: ', data.Character])
end
figure('keypressfcn','onKeyPress');
% click on the figure to give focus, press any key and check the function output in the console
Comments
If called without an argument, a new figure is created with the next available ID. If called with a free ID, a new figure is created with the free ID assigned to it. If called with a used ID, no figure is created but the figure with the ID is set as the current figure.