Loading user-defined classes from .mat files absent the classdef

14 vues (au cours des 30 derniers jours)
Matt J
Matt J le 8 Jan 2025
Commenté : Matt J le 8 Jan 2025
At one time, if I had a .mat file with a user-defined class variable, but lacked the classdef file, loading the .mat file would succeed, but convert the class property data to struct form. Now, in more recent Matlab, it fails to do that. Is there a supported way to load a user-defined object in a stripped down form, like a struct, when the class definition is absent?
  1 commentaire
Walter Roberson
Walter Roberson le 8 Jan 2025
I wonder if that struct behaviour was in the days of the older class definition, where classes were specially-blessed struct ?

Connectez-vous pour commenter.

Réponse acceptée

Steven Lord
Steven Lord le 8 Jan 2025
At one time, if I had a .mat file with a user-defined class variable, but lacked the classdef file, loading the .mat file would succeed, but convert the class property data to struct form.
That was the behavior prior to the introduction of classdef files IIRC, where the way to construct objects in the constructor function (inside the @ directory with the same name as the class) was to create a struct and call class with at least two inputs (the struct and the name of the class.) I don't remember off the top of my head if this is still the behavior for classdef based classes; I think it may load them as integer arrays, but I'm not 100% certain.
Now, in more recent Matlab, it fails to do that. Is there a supported way to load a user-defined object in a stripped down form, like a struct, when the class definition is absent?
I don't believe so. The first part of the object load process is to create an object. There is a way to modify the loading process, but it requires a method defined as part of the class.
  1 commentaire
Matt J
Matt J le 8 Jan 2025
Too bad. Well, I suppose it might provide a nice way to encrypt a mat file. Just store the data in user-defined class properties and only give the classdef to intended file recipients.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Workspace Variables and MAT Files dans Help Center et File Exchange

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by