フィルターのクリア

How can i pass a string from simulink mask to matlab function block

4 ビュー (過去 30 日間)
Tom
Tom 2022 年 8 月 8 日
編集済み: Fangjun Jiang 2022 年 8 月 9 日
Dear community,
I am trying to pass a string to a matlab function block in simulink using a mask over the matlab function block.
Firstly i don´t know how to define the string in the mask, secondly i don´t know how to access it afterwards in the function block code.
I am thankfull for your help.
Tom

回答 (1 件)

Fangjun Jiang
Fangjun Jiang 2022 年 8 月 9 日
編集済み: Fangjun Jiang 2022 年 8 月 9 日
With R2018a (with the String Constant block) or later, you can do this, with a little extra effort.
Add a 'String Constnat' block, specify the string as StrPra, to a new model, add a Display block and connect them.
In base workspace, assign StrPra="abc". Run simulation and the Display block shows "abc".
Select the String Constant block, Ctrl+M, add an 'Edit' parameter, name it as StrPra, specify value as StrPra, save mask.
Double click the masked block, it shows parameter as StrPra, change the value of StrPra in base workspace as StrPra="xyz",
run simulatioin, the Display block shows "xyz".
Or, double click, enter "MyString", run simulation, it shows "MyString".
Now the pass of a string from mask to a Simulink block has been completed. You can use it directly by a MATLAB Function block with R2020b or later. Check the supported data types at the document.
For R2020a and earlier, you will need to use a "String to ASCII" block to convert it to interger first. At the output, use a "ASCII to String" block if needed.

カテゴリ

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

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by