Referencing 1) Simulink Model Components In Subsystems and 2) Workspace variables

I need to access / change simulink model component parameters (such as gain values) when using subsystems. I can access the root level of the simulink model with "set_param([bdroot '/GainBlock1'],'Gain',str)" but how would i do the same in a subsystem. The other question I have is very similar. I would also like to change workspace variables using similar method, but again I cant get it to work. Your help really appreciated Kind regards, Ian

Answers (1)

For your first question, you should be able to the following without any issues:
>> set_param([bdroot '/Subsys/Subsubsys/BlockName'])
For your second question, what type of workspace variables are you concerned about? I'm guessing it's not the MATLAB base workspace, because those you can change directly in the Command Window:
>> x = 2;
Are you perhaps also working with model references and model workspaces?
- Sebastian

1 Comment

Thanks Sebastian, I have it working at last, although I seem to have hit another issue. I have a Simulink model that I would like to attach listeners to but not using the startfnc as I would prefer to do this dynamically as I change the current GUI figure. Unfortunately I can do this at anytime from the command line using "add_event_listener(....)" but it never works from a function. Any idea what i'm missing here. (apologies as i'm new to Matlab and this may be very obvious to most) Note: When adding the "add_event_listener(....)" into the function I don't get any errors and lines after do still work, yet no listener shown in Simulink)

This question is closed.

Tags

Asked:

on 29 Jul 2015

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!