SGwriteMAT

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Import/Export
Introduced first in SolidGeometry 4.7, Creation date: 2019-07-07, Last change: 2025-09-14

saves a Solid Geometry or other struct as mat file on disk

Description

at JHU Baltimore
In case of complex solid geometries, this is the only standard to include frames, names and other fields into the written file for export and import using matlab.
In contrast to 'save', this function allows the call without giving the file name as string

See Also: SGreadMAT

Example Illustration

 missing image of SGwriteMAT(SG,FNAME);

Syntax

FNAME=SGwriteMAT(SG,[FNAME]);

Input Parameter

SG: Solid Geometry variable name
FNAME: optinale file name for desktop write

Output Parameter

FNAME: Complete filename path name extension

Examples


SGbox([30,20,10]); SG=ans;
SGTsetofFS(SG,2,'F'); SG=ans
fn=SGwriteMAT(SG,'test')
SGreadMAT(fn); zzz=ans;
SGfigure; view(-30,30); SGTplot(zzz)




Copyright 2019-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 function, SGwriteMAT, is designed to save a Solid Geometry (SG) structure as a .mat file. It is part of the SG-Library and was created by Tim Lueth. The function is particularly useful for handling complex solid geometries, allowing for the inclusion of frames, names, and other fields in the exported file.

Input Parameters

Output

Algorithm Steps

  1. The function starts by setting a default file name using the current date in the format 'SG-yyyy-mm-dd'.
  2. The getfuncparams function is used to check if a file name was provided in the input arguments. If not, the default name is used.
  3. If the file name does not contain a file separator (indicating a directory), it is prefixed with the desktop directory path.
  4. The function retrieves the name of the input variable SG using inputname(1). If the name is empty, it defaults to 'SG'.
  5. A command string is constructed to save the variable using the save function in MATLAB.
  6. If the variable name is not local, the command is executed in the caller's workspace using evalin('caller', ss). Otherwise, it is executed in the current workspace using eval(ss).
  7. The file name is appended with the '.mat' extension.
  8. A message is printed to the console indicating that the Solid Geometry has been successfully saved as a .mat file.

Example Usage

Here is an example of how to use the SGwriteMAT function:

SGbox([30,20,10]); SG=ans;
SGTsetofFS(SG,2,'F'); SG=ans;
fn=SGwriteMAT(SG,'test');
zzz=SGreadMAT(fn);
SGfigure; view(-30,30); SGTplot(zzz);

This example creates a solid geometry box, sets some properties, saves it to a file named 'test.mat', reads it back, and plots it.

Algorithm explaination created using ChatGPT on 2025-08-19 08:14. (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