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

34 views (last 30 days)
Yasir Korai
Yasir Korai on 26 Dec 2021
Answered: Sanman on 27 Jan 2022
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 Comments
Claudio Ferrara
Claudio Ferrara on 30 Dec 2021
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

Sign in to comment.

Answers (1)

Sanman
Sanman on 27 Jan 2022
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.

Tags

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!