Here is the solution:
% Make the variable a tunable parameter
sTuneParms = get_param(bdroot, 'TunableVars');
% Append new variable to list of tunable parameters
sNewTuneParms = sprintf('%s,%s',sTuneParms, tune_name);
sStorageClass = 'Auto';
sTypeQualifier='';
for n=1:length(sNewTuneParms)
if (sNewTuneParms(n) == ',')
sStorageClass = sprintf('%s,Auto',sStorageClass);
sTypeQualifier = sprintf('%s,',sTypeQualifier);
end
end
set_param(bdroot,'TunableVars', sNewTuneParms);
set_param(bdroot,'TunableVarsStorageClass', sStorageClass);
set_param(bdroot,'TunableVarsTypeQualifier', sTypeQualifier);
% Remove the tunable parameter from the system tunable parameter
table
sTuneParms = get_param(bdroot, 'TunableVars');
n = findstr(sTuneParms, sParameterToRemove);
if n > 0
s1 = '';
for i=n:length(sTuneParms)
if sTuneParms(i) == ','
s1 = sTuneParms(1:n-1);
s2 = sTuneParms(i:length(sTuneParms));
sNewTuneParms = [s1 s2];
break;
end
end
% if no comma found then just truncate
if length(s1) == 0
if (n > 1)
if (n > 2)
if sTuneParms(n-1) == ','
sNewTuneParms = sTuneParms(1:n-2);
else
sNewTuneParms = sTuneParms(1:n-1);
end
else
sNewTuneParms = sTuneParms(1:n-1);
end
else
sNewTuneParms = '';
end
end
end
sStorageClass = 'Auto';
sTypeQualifier='';
for n=1:length(sNewTuneParms)
if (sNewTuneParms(n) == ',')
sStorageClass = sprintf('%s,Auto',sStorageClass);
sTypeQualifier = sprintf('%s,',sTypeQualifier);
end
end
set_param(bdroot,'TunableVars', sNewTuneParms);
set_param(bdroot,'TunableVarsStorageClass', sStorageClass);
set_param(bdroot,'TunableVarsTypeQualifier', sTypeQualifier);
Post by Chris PerrySorry Phil it didn't work for me.
tpTest = 1
set_param(gcs,'TunableVars','tpTest')
I get an error message - SubSystem block does not have a parameter
named 'TunableVars'
Also, once I add a parameter to the tunable parameters table, how do
I programmatically remove it?
Thanks,
-Chris
Post by Phil GoddardThere are a couple of ways to tackle this.
A. If you are using straight MATLAB variables for your
parameters,
Post by Phil Goddarde.g. you say K1 = MyValue to create the parameters, then you
need
Post by Chris PerryPost by Phil Goddardto
set the following 2 model properties.
set_param(gcs,'TunableVars','K1,K2,K3,K4');
set_param(gcs,'TunableVarsStorageClass','Auto,Auto,Auto,Auto');
If you go to the inline/tunable parameters dialog you'll see
that
Post by Chris PerryPost by Phil Goddardthe
parameters now appear just if you'd gone to that dialog to
define
Post by Chris PerryPost by Phil Goddardthem as tunable.
Have a look at the doc for set_param if you're not familiar
with
Post by Chris PerryPost by Phil Goddardthat
function.
B. Alternatively, if you are using Simulink.Parameter objects
to
Post by Chris PerryPost by Phil Goddardcreate the variables then you need to set their
RTWInfo.StorageClass
property to be anything other than auto.
Have a look in the doc for an explanation of how to do this,
and
Post by Chris PerryPost by Phil Goddardwhat
to set the parameter to.
Phil.
Post by Christopher PerryIn Simulink, if you set the inline option in the
Configuration/Optimization for your model, you can make a
parameter
Post by Christopher Perrytunable by hitting the Configure button and adding it to
the
Post by Chris PerryPost by Phil GoddardGlobal
Post by Christopher Perry(tunable) parameters list.
I want to perform the same functionality programmatically
yet I have been unable to find a Matlab command to do this?
Can this be done programmatically?