Filter löschen
Filter löschen

Re-use handles if model is closed and re-opened

3 Ansichten (letzte 30 Tage)
Joe Rustan
Joe Rustan am 27 Dez. 2022
Kommentiert: Walter Roberson am 28 Dez. 2022
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
Joe Rustan
Joe Rustan am 28 Dez. 2022
Thanks Rik. I'm not expecting the handles would work, but I would've thought the numeric identifiers of the handles would be the same so I could look them up between sessions. However, it turns these numeric identifiers are also different - sometimes just by a digit in the 3rd decimal place :) :) I was going to check the rounded-off integer but then realized sometimes even those can be different. Not sure the Mathworks logic to come up with these identifiers.
I can definitely do this with objects (in my case signal lines) that are named. I've decided to follow a different (and more cumbersome approach) of naming blank signals as Unnamed-1, Unnamed-2.... to get their handles between sessions.
Thanks again. Cheers!
Walter Roberson
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.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by