integration using s-functions in simulink

function task1(block)
setup(block);
function setup(block)
block.NumDialogPrms = 3;
block.DialogPrmsTunable={'a','b','c'};
block.NumInputPorts = 1;
block.NumOutputPorts = 1;
block.SetPreCompInpPortInfoToDynamic;
block.SetPreCompOutPortInfoToDynamic;
block.InputPort(1).Dimensions = 1;
block.InputPort(1).DirectFeedthrough = false;
block.OutputPort(1).Dimensions = 1;
block.SampleTimes = [0 0];
block.NumContStates = 1;
block.SimStateCompliance = 'DefaultSimState';
block.RegBlockMethod('InitializeConditions', @InitConditions);
block.RegBlockMethod('Outputs', @Output);
block.RegBlockMethod('Derivatives', @Derivative);
function InitConditions(block)
block.ContStates.Data = block.DialogPrm(3).Data;
function Output(block)
block.OutputPort(1).Data = block.ContStates.Data;
function Derivative(block)
a = block.DialogPrm(1).Data;
b = block.DialogPrm(2).Data;
c = block.DialogPrm(3).Data;
if (block.ContStates.Data <= a && c < 0) || (block.ContStates.Data >= b && c > 0)
block.Derivatives.Data = 0;
else
block.Derivatives.Data = c;
end
this is my code for making s-function written in script file ".m" format. it is giving the following errors-
1.Invalid setting specified for the tunability of the dialog parameters of 'task1' in 'untitled/integration'. The tunability for dialog parameters should be a [1x3] cell array of the form {'Tunable','Nontunable','SimOnlyTunable',...}.
2.Error evaluating the initialization for M-S-Function 'task1'. Invalid setting specified for the tunability of the dialog parameters of 'task1' in 'untitled/integration'. The tunability for dialog parameters should be a [1x3] cell array of the form {'Tunable','Nontunable','SimOnlyTunable',...}. The following is the MATLAB call stack (file names and line numbers) that produced this error:
['C:\Users\Admin\Downloads\The Grand Design - Stephen Hawking (Audiobook) [128k mp3] politux\task1.m'] [8]
['C:\Users\Admin\Downloads\The Grand Design - Stephen Hawking (Audiobook) [128k mp3] politux\task1.m'] [2]
how do i resolve this problem?? thanks.

回答(1 个)

block.DialogPrmsTunable must be a cell-array that contains any of the following strings: 'Tunable','Nontunable','SimOnlyTunable'. You cannot say:
block.DialogPrmsTunable={'a','b','c'};
'a', 'b' and 'c' are not valid strings.

类别

帮助中心File Exchange 中查找有关 Subsystems 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by