loading .mat file for class that no longer has dynamicprops, but now uses RedefinesDot
2 views (last 30 days)
Show older comments
Consider a class which inherits from dynamicprops. i am trying to load a .mat file containing an instance of this class.
The issue is: the class no longer uses dynamicprop but redefinesDot instead.
when the load function is called, i noticed that my DotRefference or dotAssign functions have not been called. But using the properties function i can see that all the old dynamic properties have been set onto the instance.
When trying to access this property, DotRefference is called, which should only happen for unknown properties. Resulting in my being unable to access the data behind these properties.
my ideal case would keep the current class structure, but have some custom loading to support conversion of the old .mat files to this new structure.
Does this sound like a very niche bug to you, or more like inteded incompatibility between dynamicprops and RedefinesDot?
0 Comments
Answers (1)
Sugandhi
on 25 Aug 2023
Edited: Sugandhi
on 25 Aug 2023
Hi,
I understand that when the load function is called, you noticed that DotRefference or dotAssign functions have not been called. But using the properties function you can see that all the old dynamic properties have been set onto the instance.
The issue you are experiencing with loading a .mat file containing an instance of a class that inherits from ‘dynamicprops’ but now uses ‘redefinesDot’ instead is likely due to the incompatibility between these two mechanisms for dynamic properties.
‘dynamicprops’ allows you to dynamically add and remove properties to an object at runtime, while ‘redefinesDot’ provides a way to redefine the behavior of the dot operator (.) for accessing and assigning properties.
When you load a MAT-File that contains an instance of the class, MATLAB restores the object's properties based on their names and values stored in the file. However, since the class has transitioned from using ‘dynamicprops’ to ‘redefinesDot’, the dot operator behavior is not triggered during the loading process. As a result, your ‘DotReference’ and ‘dotAssign’ methods are not called.
This behavior is expected because the loading process does not involve the dot operator (.) for accessing or assigning properties. Instead, it directly sets the properties based on their stored values.
To address this issue and support the conversion of old MAT-Files files to the new class structure, you can implement a custom loading mechanism.
For more understanding, kindly go through following links:
0 Comments
See Also
Categories
Find more on Develop Apps Using App Designer in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!