togglefig

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Visualization
Introduced first in SolidGeometry 4.3, Creation date: 2018-09-15, Last change: 2025-08-18

toggels the position of the current SGfigure

Description

moves a figure by the first call to a default position and at second back to the original position

See Also: SGfigure , copyfig , SGfigureannotation , subfig , fullview , pastego , copygo

Example Illustration

 missing image of togglefig

Syntax

togglefig

Examples


SGfigure; set (gcf,'Position',[100 200 300 400]);
togglefig; pause(1); togglefig; pause(1); togglefig




Copyright 2018-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth

Algorithm (Workflow)

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.

Input Parameters

The function does not take any input parameters. It operates on the current figure window obtained using gcf (get current figure).

Persistent Variable

The function uses a persistent variable fpos to store the original position of the figure window. This variable retains its value between function calls.

Algorithm Steps

  1. Retrieve the screen size using get(get(gcf,'Parent'),'ScreenSize') and store it in ss.
  2. Define a default figure size fs as [560 420].
  3. Calculate the default position 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.
  4. Get the current position of the figure window using get(gcf,'Position') and store it in actpos.
  5. If fpos is empty, initialize it with defpos.
  6. Check if the current position actpos is not equal to the default position defpos:
  7. Use shg to bring the figure window to the front.

Example Usage

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)

Last html export of this page out of FM database by TL: 2025-09-21