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?

EDIT

I decided to try running simple commands outside of the class to see if the problem is elsewhere. So typing in the command window:

load_system('test')
sim('test')

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.

Answers


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.


Need Your Help

Capturing file path in JAVA

java file jar path

I need to design a executable .jar which makes two text files, I want that whenever I double click the executable jar, it automatically transfer the file path to a string so that I can use it in my

Visual objects editor

java user-interface testing ide edit

I am looking for a tool which will make able to edit parts of Java code visually using something like inspector and place code back.