how to retrieve dialog values from a masked subsystem or function block using .m code?

2 views (last 30 days)
Hi
is there a way to retrieve mask dialog values from a model programatically using get_param? So far I can get the names of all the blocks in my model as well as the variables that the dialog parameters are written to but not the actual value (string or number) input into the mask.
For example: If I have a gain block in my model which I set to 'K', I'd like to have a function that returns 'K' when I send it that block or masked subsystem name.
I've been playing around with get_param but I can't seem to make it work. Looking at the mdl file as text shows the values I want are in there but I'd rather not have to use an external parser if I don't have to.
Thanks Anton
  2 Comments
Anton
Anton on 3 May 2012
Ok I've gotten a little further and can now retreive the parameters. I just need to sort them so I only see the ones that have a source in the dialog
Here's how I did it:
dialog = get_param('testModel/Layer 1-1 (layer1-1)/Saturation (layer1-2)','DialogParameters');
fields = fieldnames(dialog);
for i=1:1:length(fields)
fields{i,2} = get_param('testModel/Layer 1-1 (layer1-1)/Saturation (layer1-2)',fields{i});
end;
and the output looks like this:
'UpperLimitSource' 'Dialog'
'UpperLimit' 'layer1_SaturationUpperLimit'
'LowerLimitSource' 'Dialog'
'LowerLimit' 'layer1_SaturationLowerLimit'
'LinearizeAsGain' 'on'
'ZeroCross' 'on'
'SampleTime' '-1'
'OutMin' '[]'
'OutMax' '[]'
'OutDataTypeStr' 'Inherit: Same as input'
'LockScale' 'off'
'RndMeth' 'Floor'
So I just need to pull off the 'UpperLimit' and 'LowerLimit' parameters and I'll have what I need.
Anton
Anton on 3 May 2012
Looking inside the mdl file it's a lot easier to see which parameters have been set by the user:
Block {
BlockType Saturate
Name "Saturation (layer1-2)"
SID "4"
Ports [1, 1]
Position [235, 95, 265, 125]
BackgroundColor "white"
InputPortMap "u0"
UpperLimit "layer1_SaturationUpperLimit"
LowerLimit "layer1_SaturationLowerLimit"
the get_params function seems to be pulling from this part of the code. Looking at it it appears to be the default settings for those block types:
Block {
BlockType Saturate
UpperLimitSource "Dialog"
UpperLimit "0.5"
LowerLimitSource "Dialog"
LowerLimit "-0.5"
LinearizeAsGain on
ZeroCross on
SampleTime "-1"
OutMin "[]"
OutMax "[]"
OutDataTypeStr "Inherit: Same as input"
LockScale off
RndMeth "Floor"

Sign in to comment.

Answers (0)

Categories

Find more on Programmatic Model Editing in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!