声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1120|回复: 0

[基本模块类] 求助:将s-function名称导入模块是出错

[复制链接]
发表于 2009-1-12 15:12 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
我自己写了个最小二乘法辨识电机参数的程序,将s-function名称导入模块是出错,one or more output arguments not assigned,是真么原因,另外s-function中可以声明全局变量吗?下面是程序:
function [sys,x0,str,ts] = dsfunc(t,x,u,flag)
% An example M-file S-function for defining a discrete system.
% This S-function implements discrete equations in this form:
%      x(n+1) = Ax(n) + Bu(n)
%      y(n)   = Cx(n) + Du(n)
%
% Generate a discrete linear system:

global y1;
global out Qn Pn Kn Q1;
out=[0;0;0;0;0];
Qn=[0 0 0 0 0 ];
Pn=10^5*eye(5);


switch flag,
  case 0
    sys = mdlInitializeSizes(); % Initialization

  case 2
    sys = mdlUpdate(t,x,u); % Update discrete states

  case 3
    sys = mdlOutputs(t,x,u); % Calculate outputs

  case {1, 4, 9} % Unused flags
    sys = [];

  otherwise
    error(['unhandled flag = ',num2str(flag)]); % Error handling
end
% End of dsfunc.

%==============================================================
% Initialization
%==============================================================

function [sys,x0,str,ts] = mdlInitializeSizes()

% Call simsizes for a sizes structure, fill it in, and convert it
% to a sizes array.

sizes = simsizes;
sizes.NumContStates  = 0;
sizes.NumDiscStates  = 9;
sizes.NumOutputs     = 5;
sizes.NumInputs      = 9;
sizes.DirFeedthrough = 1; % Matrix D is nonempty.
sizes.NumSampleTimes = 1;
sys = simsizes(sizes);
x0  = ones(9,1);   % Initialize the discrete states.
str = [];          % Set str to an empty matrix.
ts  = [0.01 0];       % sample time: [period, offset]
% End of mdlInitializeSizes.

%==============================================================
% Update the discrete states
%==============================================================
function sys = mdlUpdates(t,x,u)
y1=u(5)-u(3)*u(9);
Kn=Pn*Qn/(1+Qn'*Pn*Qn);


% End of mdlUpdate.

%==============================================================
% Calculate outputs
%==============================================================
function sys = mdlOutputs(t,x,u)
Q1=[u(3);u(6);u(1);u(8)+u(9)*u(7);u(9)*u(2)];
out=out+Kn(y1-Qn'*out);
Pn=Pn-(Pn*Qn*Qn'*Pn)/(1+Qn'*Pn*Qn);
Qn=[Qn' Q1]';
sys=out;
% End of mdlOutputs.
回复
分享到:

使用道具 举报

您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-5-22 04:54 , Processed in 0.047769 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表