필터 지우기
필터 지우기

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

조회 수: 7 (최근 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 CenterFile Exchange에서 Block and Blockset Authoring에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by