フィルターのクリア

How to convert MATLAB variables to Simulink Parameters ?

9 ビュー (過去 30 日間)
Dyson Freeman
Dyson Freeman 2014 年 1 月 21 日
回答済み: Dyson Freeman 2014 年 1 月 22 日
I have several MATLAB vars in the base workspaces. Now I want to create Simulink.Parameter objects using the MATLAB vars' names. In another words, I wanna convert MATLAB variables to Simulink Parameters. All the operations need to be fulfilled in command line. Anyone who can give some help? Thanks !

採用された回答

Niklas Nylén
Niklas Nylén 2014 年 1 月 21 日
There may be some better way to do it, but this works. The storage class below is the one I use when I need to make a parameter tunable in a dSpace Autobox.
par = Simulink.Parameter;
par.RTWInfo.StorageClass = 'ExportedGlobal';
par.Value = myWorkspaceVariable;
myWorkspaceVariable = par;
  1 件のコメント
Dyson Freeman
Dyson Freeman 2014 年 1 月 21 日
Smart way! Thanks! I have modified your method to suit my problem.

サインインしてコメントする。

その他の回答 (1 件)

Dyson Freeman
Dyson Freeman 2014 年 1 月 22 日
I carefully studied this issue again, and found that there is some different between my question and the accepted answer. Because what I wanna do exactly is substituting the Simulink.Parameter for the MATLAB vars in base workspace, using batch operation in command (both have the same name but different class, respectively), the accepted answer still can not accomplish this goal since it didn't work when using for loop (The transform from var name to string have some restrictions). My code is as follows:
vars = Simulink.WorkspaceVar(who,'base workspace');
for idx = 1:length(vars)
TempValues(idx) = eval(vars(idx).Name);
str = vars(idx).Name;
eval([str '= Simulink.Parameter;']);
eval([str '.Value = TempValues(idx);']);
eval([str '.StorageClass = ' '''ExportedGlobal''' ';']);
end

カテゴリ

Help Center および File ExchangeString についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by