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

6 visualizaciones (últimos 30 días)
Tom el 8 de Ag. de 2022
Editada: Fangjun Jiang el 9 de Ag. de 2022
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.

Respuestas (1)

Fangjun Jiang
Fangjun Jiang el 9 de Ag. de 2022
Editada: Fangjun Jiang el 9 de Ag. de 2022
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.


Más información sobre Subsystems en Help Center y File Exchange.




Community Treasure Hunt

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

Start Hunting!

Translated by