[enter image description here][1]
Hi. I created matlab level-2 s-function where i want a user to put two parameters. How am i supposed to add second field for a second parameter (and not just type them separated with comma)? And also how am i supposed to rename these parameters? [1]: https://i.stack.imgur.com/xHKZT.png
Here is code of my s-function:
function s_func_fan(block)
% Вызов блока для подготовки
setup(block);
%endfunction
%%
function setup(block)
% Register number of ports
block.NumInputPorts = 2;
block.NumOutputPorts = 1;
% Setup port properties to be inherited or dynamic
block.SetPreCompInpPortInfoToDynamic;
block.SetPreCompOutPortInfoToDynamic;
% Override input port properties | RPMs
block.InputPort(1).Dimensions = 1;
block.InputPort(1).DatatypeID = 0; % double
block.InputPort(1).Complexity = 'Real';
block.InputPort(1).DirectFeedthrough = true;
% Override input port properties | Diameter
block.InputPort(2).Dimensions = 1;
block.InputPort(2).DatatypeID = 0; % double
block.InputPort(2).Complexity = 'Real';
block.InputPort(2).DirectFeedthrough = true;
% Override output port properties
block.OutputPort(1).Dimensions = 1;
block.OutputPort(1).DatatypeID = 0; % double
block.OutputPort(1).Complexity = 'Real';
% Register parameters
block.NumDialogPrms = 2;
%block.DialogPrms = {'A', 'B'};
% Register sample times
% [0 offset] : Continuous sample time
% [positive_num offset] : Discrete sample time
%
% [-1, 0] : Inherited sample time
% [-2, 0] : Variable sample time
block.SampleTimes = [0 0];
% Specify the block simStateCompliance. The allowed values are:
% 'UnknownSimState', < The default setting; warn and assume DefaultSimState
% 'DefaultSimState', < Same sim state as a built-in block
% 'HasNoSimState', < No sim state
% 'CustomSimState', < Has GetSimState and SetSimState methods
% 'DisallowSimState' < Error out when saving or restoring the model sim state
block.SimStateCompliance = 'DefaultSimState';
%% -----------------------------------------------------------------
%% The MATLAB S-function uses an internal registry for all
%% block methods. You should register all relevant methods
%% (optional and required) as illustrated below. You may choose
%% any suitable name for the methods and implement these methods
%% as local functions within the same file. See comments
%% provided for each function for more information.
%% -----------------------------------------------------------------
block.RegBlockMethod('Outputs', @Outputs); % Required
block.RegBlockMethod('Terminate', @Terminate); % Required
%end setup
function Outputs(block)
%% Исходные данные
n = block.InputPort(1).Data; % Частота вращения вентилятора, об/мин
d = block.InputPort(2).Data; % Диаметр вентилятора, м
r = d/2; % Радиус вентилятора, м
rho = block.DialogPrm(1).Data; % Плотность воздуха, кг/м^3
r0 = block.DialogPrm(2).Data; % Расстояние от вентилятора до приемника, м
omega = 4*pi; % Характеристика затухания звука в замкнутом помещении
V = (2 * pi * r * n / 60) / 6; % Скорость воздуха на выходе из вентилятора, м/с
%% Расчет мощности звука и уровня звуковой мощности
P = 0.5 * rho * V^2 * pi * r^2 * 0.8; % Мощность звука, Вт
Lw = 10*log10(P/(1e-12)); % Уровень звуковой мощности, дБ
%% Расчет уровня звука в заданной точке
Lp = Lw - 15 * log10(r0) - 10*log10(omega); % Уровень звука в заданной точке, дБ
Lp = Lp/3;
block.OutputPort(1).Data = Lp;
%end Outputs
%%
%% Update:
%% Functionality : Called to update discrete states
%% during simulation step
%% Required : No
%% C MEX counterpart: mdlUpdate
%%
function Terminate(block)
%end Terminate