Simulink mask using base workspace variables and mask workspace parameters in same expression

14 views (last 30 days)
Hello,
I'm creating a masked block where user will enter value of ID mask parameter and based on and a data structure in base workspace the mask will set properties of some block inside subsystem.
The data structure looks like this:
Servo(1).us.min = 10;
Servo(1).us.max = 50;
Servo(2).us.min = 500;
Servo(2).us.max = 100;
It is created and stored in MATLAB base workspace.
In subsystem mask Parameters & Dialog user is choosing ID value ranging between 1 and 2.
Now the subsystem is supposed to set some block parameter value according to the picked ID, it should happen on block initialization and every time mask parameter ID is changed.
In order to achieve that, first I created two hidden mask parameters LL and UL and used them in a block of my choice and then in Initialize and ID_callback im setting their values with evalin() because i knew it could be used to access base workspace from mask. Here is the mask code:
% Initialization code section
function initialization()
UL = evalin('base','Servo(ID).us.max')
LL = evalin('base','Servo(ID).us.max')
end
% Parameter callback section
% Callback for ID
function ID_callback()
UL = evalin('base','Servo(ID).us.max')
LL = evalin('base','Servo(ID).us.max')
end
And well, all would be fine if only mask would use base workspace parameters exclusively (or only mask workspace paramters) but I want to use them both in a single expression.
Even is Servo is a base workspace parameter the ID is mask workspace paramter so if I'm using evalin() im getting error that ID is undefinied and if I'm not using evalin I'm getting error that Servo is undefinied.
Is there any way to do what I want to achieve?

Answers (0)

Community Treasure Hunt

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

Start Hunting!