How to pass value to params of masked subsystem from m files and restore the output from simulink operation each time?

Hi everyone, I have one problem if the subsystem is masked, then the workspace for all variables masked within the subsystem is different from the matlabe base workspace. Here is problem which I met. (1). the values of variables [x] for masked susystem are defined in matlab base workspace, (2).the run the "sim" for simulink, (3). return the {output(from the output port); x} to workspace for further operation (4). the main code computes and give new [x'] for next operation of the simulink. (5). repeat the same process of step (1). this is a little different from single call sim. The second iteration stuck after (5), which means the transfer of variables fail.
Could you give me some suggestion and help? Again many thanks.

 Accepted Answer

It is true that the parameters inside a masked subsystem are isolated from the base workspace. But those parameters are supposed to interface with the base workspace through the mask parameter dialog. Let's say your masked subsystem has a variable called x_param. It has a value in the base workspace. After one simulation is done, you can use set_param() to change the parameter to be x2_param. Or simply change the value of x_param in the base workspace. Next time the simulation is run, it should take effect.
I don't think your problem is particularly with the masked subsystem. Try to go through your steps manually. I mean, don't run script initially trying to automate the whole thing in one shot. Just follow your step manually, even run the simulation using the "play" button, not to use the sim() command. Try to sort through each step to see where things are broken.

1 Comment

Yes, first thank you for solution.
Your suggestion is quite helpful for me. The process step-by-step succeeds. I am moving to the next level.
Best wishes for you!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!