Determine if script will crash due to Read-Only model workspace

1 次查看(过去 30 天)
I have a script which can be called either from a block's mask parameters being changed, or from the same block's "copyfcn" callback. For the most part this works well, as the same script which updates the block based on mask parameters is run when a newer version of the block's template is copied in. However, I am having trouble with one part of my script which interacts with a variable in the model workspace.
When this script is run from the mask parameter, it works. But when it is run during the model's initialization, the model workspace is read-only, and my interaction with the modelworkspace variable makes my script crash. I know I can see which variables are in the modelworkspace with the "who" property, but to make this work I also need to know the size of the variables, and I can't figure out a way to get that information without using "evalin", which crashes with a read-only workspace.
This part of the script doesn't necessarily need to run as the model initializes, so if I could detect model run state or modelworkspace read-only state, I could add an "if" condition around the offending part of my script, but I can't find a way to detect this either. I try to avoid using "try" lines in my scripts. Is there any other way to do this?

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programmatic Model Editing 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by