How can I parametrize the "To Workspace" block in Simulink?
7 ビュー (過去 30 日間)
古いコメントを表示
Krishnanand K.R.
2014 年 7 月 31 日
編集済み: Krishnanand K.R.
2014 年 8 月 4 日
Hi there. I am trying to parametrize the "To Workspace" block in Simulink, but it shows me error. Instead of the default variable name simout , I want to use a name that I can pass from workspace. Ex: eval('HHH') instead of simout , where HHH='some_var' . Then the signal from simulation should be stored in a variable named some_var in the base workspace.
The actual scenario is a bit more complex. I would want to provide variable name through eval('B.Label') , where the field Label of the structure B is initialized in the base workspace as B.Label='some_var' . Otherwise, B could be an internal variable in the mask of the subsystem that contains the "To Workspace" block.
The variable name is never changed during the simulation. Thanks in advance for any helpful suggestions.
These are the inputs I tried instead of the default simout, but they gave error Invalid MATLAB variable name specified in ...
eval('B.Label')
B.Label
0 件のコメント
採用された回答
Christopher Berry
2014 年 8 月 4 日
Hi Krishnanand,
Since the variable name does not change during the simulation, you can set the output parameter 'VariableName' of the 'To Workspace' block completely from the base workspace like this:
First, you will need to get the system path for the 'To Workspace' block in question. You can do this interactively by selecting that block and then typing:
>> h = gcb;
or you can do this at the cmd prompt by typing:
>> h = find_system(gcs,'Name','To Workspace')
Where 'To Workspace' is the exact name of the block you want to manipulate. If you have more than one 'To Workspace' block, make sure to pick the right one!
Either way, the system path for the block will not change unless you change it, so you will only need to do this once after you create your model.
Then, before you start your simulation, just execute the following lines:
>> B.Label = 'test_struct_name';
>> set_param(h,'VariableName',B.Label);
Then you shoudld be good to go!
2 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Choose and Parameterize Blocks についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!