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

28 ビュー (過去 30 日間)
Yasir Korai
Yasir Korai 2021 年 12 月 26 日
回答済み: Sanman 2022 年 1 月 27 日
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 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,
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.
Hope this helps.





Community Treasure Hunt

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

Start Hunting!

Translated by