Simulink Variable Scope HELPP

8 views (last 30 days)
Cyrus
Cyrus on 2 Mar 2016
I am calling a simulink model within a for loop to perform a linearization on the model. The problem is that all the workspace defined variables that are embedded in my simulink model fall out of scope of the work space for some reason. It thinks they are undefined function or variables. If I define the variables outside the work space, the code runs fine; however, the problem is that they are changing each pass of the for loop. I could fix it by making them global at the start of the main script, but I would like to avoid that.
Here is my code snipit:
for i=1:end block_variables_for_inner_loop = defined_here; sys = 'innerloop'; load_system(sys); sys_io('set I/O point'); linsys = linearize(sys); <- CRASH, I cant find block_variables_for_inner_loop variables to assign values to the blocks of sys margin(linsys);
end
The variables inside my blocks of my .mdl file, 'innerloop' are based on inside the for loop. I cant believe such a basic basic thing like this doesnt work out of the box. I have read about using simset, but that only work is you are running the sim. It seems like it does not help in my application.

Answers (0)

Categories

Find more on Event Functions in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!