SGreadMAT

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

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

Description

..see SGwriteMAT..
This function allow to read in a SG struct with a generated information that would disappear since the STL format does not support Frames etc.

See Also: SGwriteMAT , SGreadSTL , SGreadOBJ

Example Illustration

 missing image of SGreadMAT(FName)

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

Output Results

Algorithm Steps

  1. The function begins by retrieving the filename parameter using the getfuncparams function. If no filename is provided, it defaults to an empty string.
  2. 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.
  3. Once a filename is obtained, the function prints a message indicating the file being loaded.
  4. The .mat file is loaded into a structure using the load function. This structure is stored in the variable rstruct.
  5. The function retrieves the field names of the loaded structure using fieldnames and stores them in the variable fn.
  6. The first field of the structure is extracted using getfield and assigned to the output variable SG.
  7. If the loaded structure contains more than one field, a warning is issued indicating that only the first variable is returned.
  8. 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:
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