Matlab Simulink, how to pass a string as a mask parameter?

30 次查看(过去 30 天)
I am currently developing a custom matlab function simulink block.
I have 2 normal inputs and a third input as a mask parameter in a combobox. If I modify my function so that the parameter should be a number everything works(you just have to tick the evaluate checkbox in the mask editor), if I use a function that needs that parameter to be a string I receive the classic error:
Expression 'parametername' for initial value of data 'parametername' must evaluate to specified type string.
So my question is how can I set my block to receive a string as an input parameter?
If I turn the parameter to a normal input everything works, but I don't like to have such type of input organization.
It would be still okay to have as real input parameter number but show in the combobox corresponding names.
Thank you in advance and Merry Christmas.
  2 个评论
Claudio Ferrara
Claudio Ferrara 2021-12-30
编辑:Claudio Ferrara 2021-12-30
Hi I have the same problem, I have noticed that if you create a combobox with a list of strings matlab creates a sort of hidden enumeration class so in the matlab function the third string passes as 3 for example. You just have to deselect evaluate and tunable both from the mask editor and the ports and data manager
If you want to pass a string another solution I have found is to input the string as a normal input from a constant string block, than create a subsystem of the string block and matlab function block. Then create a mask of the subsystem and promothe the string value of the string block as a parameter. Remeber also in this case to deselect tunable and evaluate in both the mask editor and the ports and data manager.
Let me know if you find a proper solution, because I have a very similar problem

请先登录,再进行评论。

回答(1 个)

Sanman
Sanman 2022-1-27
Hi Yasir,
As far as I understand, while setting a mask param value, a value is supposed to be provided in a string format. For example, if you want to set a double value, you need to call set_param in the following way,
set_param(<blkname>,<paramName>,'20')
This value eventually gets evaluated while the value is being set.
In your case, since you want to set a string value, you would need to nest the value while calling set_param.
set_param(<blkname>,<paramName>,'"stringVal"')
Hope this helps.

类别

Help CenterFile Exchange 中查找有关 Simulink Functions 的更多信息

标签

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by