S函数,一直报错“带有下标的赋值维度不匹配。
古いコメントを表示
在simulink中准备建个S函数的,可是一直报错,如下。
“在执行S函数时flag = 2 (update), at time 0.0. 带有下标的赋值维度不匹配。”
我的程序如下,是红色出有错吗,求大神帮忙,谢谢!
function [sys,x0,str,ts]=han_eso(t,x,u,flag,bet,b,T)
switch flag,
case 0
[sys,x0,str,ts] = mdlInitializeSizes; % 初始化
case 2
sys = mdlUpdates(x,u,bet,b,T); % 离散状态的更新
case 3
sys = mdlOutputs(x); % 输出量的计算
case { 1, 4, 9 }
sys = []; % 未使用的flag值
otherwise
error(['Unhandled flag = ',num2str(flag)]); % 处理错误
end;
function [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes
sizes = simsizes;
sizes.NumContStates = 0;%无连续变量
sizes.NumDiscStates = 2;%2个离散变量
sizes.NumOutputs = 2;%2路输出
sizes.NumInputs = 2;%2路输入:u和w
sizes.DirFeedthrough = 0;%输入信号不直接在输出中反映出来
sizes.NumSampleTimes = 1; % at least one sample time is needed
sys = simsizes(sizes);
x0 = [0;0]; %设置初始状态为零状态
str = []; %将str变量设置为空字符串
ts = [-1 0]; %采用周期;假设它继承输入信号的采样周期
simStateCompliance = 'UnknownSimState';
function sys=mdlUpdates(x,u,bet,b,T)
sys(1,1) = x(1)+T*(x(2)-bet(1)*(x(1)-u(2))+b*u(1)); %u(1)为bo*iq,u(2)为w
sys(2,1) = x(2)-T*bet(2)*(x(1)-u(2));
function sys=mdlOutputs(x)
sys = x;
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で MATLAB Support Package for Raspberry Pi Hardware についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!