How can i pass a string from simulink mask to matlab function block
조회 수: 4 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (1개)
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 String에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!