Simulink difference between load_system and open_system
I have a Simulink model that calls a script in the InitFcn of the Model callbacks. This script initializes a bunch of variables in the base workspace so that they can be used by the Simulink model. When using Classes, I found that using the load_system function will make Matlab crash and the open_system function will work just fine.
Here the Class:
classdef simulinkModel properties model = ''; end methods function obj = simulinkModel(modelName) obj.model = modelName; end function openModel(obj) % Make sure any previously open model are closed, and open the model. if bdIsLoaded(obj.model) obj.closeModel() end %load_system(obj.model) % Matlab crash open_system(obj.model) % Matlab run the model correctly end function closeModel(obj) close_system(obj.model, 0) end function runModel(obj) sim(obj.model) end end end
And in the command window:
objModel = simulinkModel('test'); objModel.openModel objModel.runModel
So how comes it crashs with the load_system vs the open_system? Is there something that the open_system function do with the base workspace that the load_system function doesn't do?
I decided to try running simple commands outside of the class to see if the problem is elsewhere. So typing in the command window:
When executing this in the command window, Matlab will also crash. So I'm starting to wonder if the model callbacks are not executed when the load_system function is called.
I can confirm there is indeed very different behaviour between load_system and open_system. I am currently debugging a weird problem under 2015b to be, and I just realized the LoadFcn callback of my simulink models is not called when I use load_system, but is is called properly when I use open_system. I don't know that this is documented anywhere. I find this callback name misleading if it is not called when you "load" the system !!! If I find more info, I will post back on this thread.