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

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.

Related

How to create Input dialog box in matlab?

I want to create input dialog box in matlab. I am performing simple addition operation in MATLAB.
Two variables name, a and b are needed to be given by user and then performing addition c=a+b; and display it in output. Both a and b should be positive integer only.
I tried following:
a = inputdlg({'Enter positive integer (a)'});
b = inputdlg({'Enter positive integer (b)'});
c=a+b;
But it is giving following error:
Undefined function or method 'plus' for input arguments of type
'cell'.
Please suggest how can i code the above program in described way.
That's because the output of inputdlg is a cell array containing a string; here a 1-cell array.
Hence you need to access the content of the cell array to perform the operation; for example using {curly brackets} : {a} and {b}.
In your case, since you are asking the use for a number, you need to convert the output, which is a string, to an actual number Matlab can use using for instance str2double, which operates on cell arrays
c = str2double(a) + str2double(b)

Is it possible to use to set a parameter in Simulink without running a Matlab script?

When a Simulink model contains a parameter, its value can be set using a script.
For instance, a constant block could have the value a, and the script would then contain the expression a=2 to set its value.
Is it possible to set the parameter inside the Simulink model, without running a Matlab script?
For instance, the Simulink model could containa drop-down menu that alows you to set the value of the parameter.
Possible solutions include
Making your own GUI (see GUIDE)
Using masked subsystems
Using Simulink Dashboard blocks

Simulink: How does one assign a double to a constant in a subsystem through the mask?

This is a slightly long-winded problem, but should be easy to follow along.
End goal: Input a 'double' vector into a C++ S Function by assigning it to a Constant.
Starting point: A function within the Dialog Callback of my masked subsystem returns the double vector that I need.
Steps in the middle: So I have a double vector as an input, I need a double vector as an output, but I cannot pass the vector directly, because set_param requires that I pass the value as a string.
Problem: What I tried is this: set_param(gcb,'refNameArray',num2str(refName));
where,
gcb (correctly) returns the block from within which I am doing
everything.
refNameArray is the parameter which needs to be assigned
the double vector
refName is the vector, in 'double' form, that I
have available within the dialog callback of the mask.
I use num2str because I cannot directly assign a vector, I must input it as a string.
But, even using num2str, I get an error saying Invalid Setting in Block <blockName> for parameter 'Value'.
Any suggestions?
The value you set for param in the dialog should be syntactically similar to an RHS expression in MATLAB. For example, for a vector value you would need to set it as '[1 3 4]'. Notice the square brackets. num2str does not add that square brackets. You can either add it manually at the ends before calling set_param or you can use mat2str which will create the string with the brackets.

changing value of parameter not given in input ports with each loop iteration in simulink

Can anybody tell me how to change value of a parameter which is not given in input ports of that block during each iteration of 'while' or 'for' loop in any block in simulink for example, if i want to plot 'throughput' against 'SNR' which is a parameter in 'awgn channel' block (which takes only data to be transmitted as input, I change 'SNR' parameter manually) how can it be done automatically with loop iterations?

MATLAB set_param for From Wave Device

How to set the parameters of a from wave device block in a simulink model?
I need to set the "samples per frame" parameter. It must be something like ('Model Name/ From Wave Device','Samples Per Frame',1024) ... but it does not work like this.
Is it possible to set the parameters of this block?
Most Simulink blocks use the dialog prompt as the parameter name, but without the spaces. So in this case, you would use,
>> set_param('model/blockName','SamplesPerFrame','1024');
Also, since the block accepts a workspace variable as the value, you should set it as a string, so use '1024', not 1024. One other tip is to use Tab completion, so you could have typed,
>> set_param('model/blockName','S[tab]
and this would have shown you a list of possible parameters that start with S.