How to set a string as an input parameter for a matlab function block?

64 次查看(过去 30 天)
Hi, I am trying to set a string as an input mask parameter in a matlab function block in Simulink but it has been a nightmare. So i have set my input as parameter in the ports and data manager, i have created in the mask editor a parameter with the same name. If I use numbers everything works, with strings no.
Actually if you deselect tunable and if you use a popup containing a list of strings in the mask editor simulink creates a sort of hidden enumeration class so the first string corresponds to the number 1 and so on, but this is not what i would like to achieve.
I can pass a string as a normal input using the constant string block, but I would like to write the string using the mask of the block.
Anyone that could help me please?

采纳的回答

Pranjal Kaura
Pranjal Kaura 2021-12-31
Hey Claudio,
A workaround could be to specify the format of the input data as 'uint8', you will be able to define the string in the mask and have it implicitly imported. You will then need to edit the code to convert the uint8 array into a character array for use with your function. We already have an enhancement request for this functionality recorded and our development team is currently in the process of reviewing this request.
The attached example does just that.
Hope this helps!
  2 个评论
Claudio Ferrara
Claudio Ferrara 2021-12-31
编辑:Claudio Ferrara 2021-12-31
Thank you very much, I have matlab 2019b, could you give me a compatible example please, so I can understand better?
Claudio Ferrara
Claudio Ferrara 2021-12-31
Don't worry I have understood. So you do this:
  • open the function and in the port and data manager set parameter, int8 and tunable, than in the function write char(input:name)
  • open the mask editor, create a edit parameter with the same name and write something like int8('desired_string')
Not so great, but this is what we have now.

请先登录,再进行评论。

更多回答(1 个)

Claudio Ferrara
Claudio Ferrara 2021-12-31
BTW I have found a better workaround imo:
- I put the parameter as a normal input
- The input is linked to a a constant string block
- I create a subsystem of the Matlab function block and the string block
- I create a mask of this new subsystem and I promote the string value of the string block as a parameter.
This is not the best solution, but it is ok.

类别

Help CenterFile Exchange 中查找有关 Interactive Model Editing 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by