How to create variable system in S-Function using feedback data from simulink or workspace)
Show older comments
Hello
Here,continues steady-space system is defined in S-Function block in simulink:
if true
function [sys,x0,str,ts] = mycsfunc(t,x,u,flag)
% x' = Ax + Bu
% y = Cx + Du
%
% Generate a continuous linear system:
A=[-1 -10
1 0];
B=[ 1 -20
0 -2];
C=[ 9 2
1 -5];
D=[-14 0
1 3];
%
% Dispatch the flag.
%
switch flag,
{1,3,9}
...
..
.
%
End of mycsfunc.
%==============================================================
% mdlInitializeSizes
% Return the sizes, initial conditions, and sample times for the
% S-function.
%==============================================================
%
function [sys,x0,str,ts] = mdlInitializeSizes(A,B,C,D)
%
% Call simsizes for a sizes structure, fill it in and convert it
% to a sizes array.
%
sizes = simsizes;
sizes.NumContStates = 2;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 2;
sizes.NumInputs = 2;
sizes.DirFeedthrough = 1; % Matrix D is nonempty.
sizes.NumSampleTimes = 1;
sys = simsizes(sizes);
...
..
.
End of mdlOutputs.
end
In simulink I have a variable prameters that can effect my system parameters. K is a parameter in simulink or workspace that can change continuously.How can I define this parameter to my s-function to get K , P data from simulink or workspace to create variable system like below in S-Function:(How to create variable parameter dependent system in S-Function as below)
if true
A=[-1 -P
1 0];
B=[ 1 -20
0 -2];
C=[ 9 2
1 -5];
D=[-K 0
1 3];
end
Thanks
Accepted Answer
More Answers (0)
Categories
Find more on Event Functions in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!