Re-use handles if model is closed and re-opened
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
This is in Matlab 2019b.
I have a function to read/calculate signal information from a Simulink model (model1.slx) and produce a list of matching signal handles. This function is quite time-consuming, so I save the output of signal handles to a table in a MAT file. The next time, I want to just read these handles from the MAT file rather than recalculate.
All of this works, except the signal handles are shown as invalid/deleted when I close model1.slx and re-open it. Nothing has changed in the model, but the handles are no longer valid. I have compared them one-by-one and the handle numbers are exactly the same before and after.
Is there any way to keep object handles 'persistent' for re-use when a model is closed and re-opened or across multiple sessions of Matlab? Any other suggestions to achieve this without having to re-compute each time would be greatly appreciated.
TIA
Joe
3 Kommentare
Walter Roberson
am 28 Dez. 2022
The numbers you see are closely related to the old handle graphics numeric handles. Before handles got made into a class primarily in R2014b, the interface to the user was to represent them to the users as double precision numbers. The same double precision representation was used for Simulink objects.
The double precision representation for handles is still available internally. You can double() a handle to see the number and you can handle() a number to get the handle object it is associated with. You can still do things like figure(3) and that is treated like figure(handle(3))
The numbers you are seeing in Simulink are not random... they are equivalent to pointers. Items tend to get allocated different locations in memory when they are recreated.
Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!