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
- SG: The Solid Geometry variable that you want to save.
- FNAME (optional): The desired file name for the saved .mat file. If not provided, a default name is generated.
Output
- FNAME: The complete file path and name of the saved .mat file.
Algorithm Steps
- The function starts by setting a default file name using the current date in the format 'SG-yyyy-mm-dd'.
- The
getfuncparams
function is used to check if a file name was provided in the input arguments. If not, the default name is used.
- If the file name does not contain a file separator (indicating a directory), it is prefixed with the desktop directory path.
- The function retrieves the name of the input variable
SG
using inputname(1)
. If the name is empty, it defaults to 'SG'.
- A command string is constructed to save the variable using the
save
function in MATLAB.
- 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)
.
- The file name is appended with the '.mat' extension.
- 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