Home How to use SimulationInput object as property of a handle class
Reply: 0

How to use SimulationInput object as property of a handle class

rotton
1#
rotton Published in 2018-02-13 14:05:22Z

There seems to be a bug when using the "new" (since R2009b) sim command in conjuction with handle classes. I am trying to migrate my obsolete code using simset to the new version.

Consider this simple class:

classdef SimulationClass < handle
    %SimulationClass Simulate process using model 
    properties
        modelFilename char
        simInp
        simulationTime double
    end

    methods
        function obj = SimulationClass(simulationTime)
            obj.simulationTime = simulationTime;
        end

        function prepareSimulation(obj, modelFilename)
            obj.modelFilename = modelFilename;
            obj.simInp = Simulink.SimulationInput(obj.modelFilename);
            obj.simInp.setModelParameter('Solver', 'ode15s',...
                    'OutputOption', 'RefineOutputTimes');
        end

        function runSimulation(obj)
            simulationResults = sim(obj.simInp);
        end
    end
end

Again, I run

mySim = SimulationClass(1:10);
mySim.prepareSimulation('mySimulinkSheet');

But the resulting mySim.simInp object is empty, except for the ModelName. Also, this does not work either:

mySim.simInp.setModelParameter('Solver', 'ode15s','OutputOption', 'RefineOutputTimes');

Can anyone confirm this, please? Is this a similar bug as the one in the linked question? Is there a workaround?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 6.068524 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO