m-code S-function don't works with MATLAB Function "int" (definte or indefinite integral in MATLAB code)
1 次查看(过去 30 天)
显示 更早的评论
Hi,
I need to create a s-function block in simulink, to integrate a function but not respect to time (respect to an other function). I make this code:
function msfuntmpl_basic(block)
setup(block);
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
block.InputPort(1).Dimensions = 1;
block.InputPort(1).DatatypeID = 0; % double
block.InputPort(1).Complexity = 'Real';
block.InputPort(1).DirectFeedthrough = true;
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 = 0;
block.SampleTimes = [0 0]; % <<<<--------------------- SAMPLE TIME
block.RegBlockMethod('Outputs', @Outputs); % Required %
block.RegBlockMethod('Terminate', @Terminate); % Required %
function Outputs(block)
%block.OutputPort(1).Data = block.InputPort(1).Data + block.InputPort(2).Data;
block.OutputPort(1).Data = int(block.InputPort(1).Data); %integrate function from Symbolic Math Toolbox.
function Terminate(block)
But simulink does this error message: "Error evaluating registered method 'Outputs' of M-S-Function (name of m-file.m)in 'untitled/Level-2 M-file S-Function1'. Undefined function or method 'int' for input arguments of type 'double'."
I think that s-function don't call "int" function like matlab editor (from Symbolic Math Toolbox). What function can i use for this purpose ?
0 个评论
回答(3 个)
Kaustubha Govind
2011-3-15
If you're trying to implement an integrator (w.r.t time) using MATLAB-file S-functions, see the demo msfcndemo_limintm.mdl. You can just type "msfcndemo_limintm" at the MATLAB prompt to open it up. Unless you are performing custom operations, you can simply use the Integrator block from the Simulink library instead.
4 个评论
Kaustubha Govind
2011-3-16
In that case, Walter's alternate suggestion for integrating step-by-step might be more appropriate.
Walter Roberson
2011-3-15
int is for symbolic integration, not for numeric integration. trapz would be more appropriate, if you can somehow gather the complete input signal up.
2 个评论
Walter Roberson
2011-3-15
Yes, that is the more difficult part, and is why you should likely follow Kaustubha's suggestions. Either that or integrate step by step, with some kind of signal to tell it to zero the total, and each signal after that gets added to the total; this might call for one or two persistent variables.
Gigi Dioda
2011-6-27
Hi, all! I have a simpler issue. I want to integrate an S-function with ode45. It seemed to work. However it's not the result I was expecting. After that I took the code from the S-function and plugged into a regular dx = f(t,x,u) function and when I applied ode45 to f I got what I was looking for.
So, my question: what's wrong with ode45 and the S-function?
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!