togglefig
SGfigure; set (gcf,'Position',[100 200 300 400]);
togglefig; pause(1); togglefig; pause(1); togglefig
This algorithm is a MATLAB function named togglefig
that toggles the position of the current figure window between a default position and its original position. It is part of the SolidGeometry library and was introduced in version 4.3.
The function does not take any input parameters. It operates on the current figure window obtained using gcf
(get current figure).
The function uses a persistent variable fpos
to store the original position of the figure window. This variable retains its value between function calls.
get(get(gcf,'Parent'),'ScreenSize')
and store it in ss
.fs
as [560 420]
.defpos
for the figure window using the screen size and default figure size. The default position is set to the top-left corner of the screen with a margin of 100 units from the top.get(gcf,'Position')
and store it in actpos
.fpos
is empty, initialize it with defpos
.actpos
is not equal to the default position defpos
:defpos
and update fpos
with actpos
.fpos
.shg
to bring the figure window to the front.The function can be used as follows:
SGfigure; set(gcf,'Position',[100 200 300 400]); togglefig; pause(1); togglefig; pause(1); togglefig;
This example creates a figure, sets its position, and then toggles its position twice with a pause of 1 second between each toggle.
Algorithm explaination created using ChatGPT on 2025-08-18 23:53. (Please note: No guarantee for the correctness of this explanation)