How to create variable system in S-Function using feedback data from simulink or workspace)

3 ビュー (過去 30 日間)
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

採用された回答

Kaustubha Govind
Kaustubha Govind 2014 年 8 月 27 日
You can simply add additional parameters to the main function as follows:
function [sys,x0,str,ts] = mycsfunc(t,x,u,flag,P,K)
and use these within the function and/or pass them onto to mdlInitializeSizes, mdlOutputs, etc.
On the S-function block, enter values for P and K (in that order) in the "S-function parameter" edit-box. These values can be constant numbers or mask/workspace variables, just like for other block parameters.
Also, note that you are using Level-1 S-functions which have been deprecated for several years and have a lot of limitations. I would recommend that you convert to Level-2 S-functions if possible.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeBlock and Blockset Authoring についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by