Reading the documentation on the creation of custom event.EventData objects I found the following puzzling note:
To save and load objects that are subclasses of event.EventData, such as ToggleEventData, enable the ConstructOnLoad class attribute for the subclass.
Checking further , I found that ConstructOnLoad allows one to automatically call the constructor of a class upon 'deserialising' a class from a .mat file.
However, for that to work, there should be a constructor with no arguments:
Ensure that MATLAB can call the class constructor with no arguments without generating an error.
However, in the doc on event.EventData, an example is given with a constructor that takes a parameter and without a loadobj!
classdef (ConstructOnLoad) ToggleEventData < event.EventData
function data = ToggleEventData(newState)
data.NewState = newState;
This is highly confusing to me.
No mention is made as to why it would be smart to add the ConstructOnLoad attribute and what would be the consequence of not having it. No background is provided.
This will cause users to add the attribute by default without knowing what it is for.
As such, the documentation should probably be improved.
That being said, I would love to hear from the experts what would be the reason for adding the attribute.