Syntax
SG=SGreadMAT([FName])
Input Parameter
FName : | | Filename of mat file to read |
Output Parameter
SG : | | struct read from file |
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, SGreadMAT, is designed to load a Solid Geometry (SG) structure from a .mat file. It is part of the SG-Library and was created by Tim Lueth in 2019. The function is primarily used for reading SG structures that contain information not supported by the STL format, such as frames.
Input Parameters
- FName: The filename of the .mat file to be read. If not provided, the function will prompt the user to select a file using a file dialog.
Output Results
- SG: The structure read from the file. This is the main output of the function.
Algorithm Steps
- The function begins by retrieving the filename parameter using the
getfuncparams
function. If no filename is provided, it defaults to an empty string.
- The function then attempts to open a file dialog to select a .mat file if the filename is not specified or is empty. This is done using the
tryuigetfile
function with a filter for .mat files.
- Once a filename is obtained, the function prints a message indicating the file being loaded.
- The .mat file is loaded into a structure using the
load
function. This structure is stored in the variable rstruct
.
- The function retrieves the field names of the loaded structure using
fieldnames
and stores them in the variable fn
.
- The first field of the structure is extracted using
getfield
and assigned to the output variable SG
.
- If the loaded structure contains more than one field, a warning is issued indicating that only the first variable is returned.
- If no output argument is specified and the loaded structure is a valid SG structure (checked using
isSG
), the function proceeds to visualize the structure:
- It opens a new figure using
SGfigure
and sets the view angle to (30, 30).
- The function extracts the file name and extension using
fileparts
and constructs a title string using titleofcaller
.
- The title is set for the figure, and the SG structure is plotted using
SGTplot
.
- Finally, a light source is added to the plot using
camlightTL
.
Algorithm explaination created using ChatGPT on 2025-08-19 07:27. (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