马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
错误提示为:Error in 'untitled/S-Function' while executing M-File S-function 'conv_encode', flag = 3 (output), at time 0. MATLAB error message:
Index exceeds matrix dimensions.
我的程序为:
function [sys,x0,str,ts] = conv_encode(t,x,u,flag,G,k)
switch flag,
case 0
[sys,x0,str,ts]=mdlInitializeSizes(G,k);
case 3
sys=mdlOutputs(t,x,u,G,k);
case {1,2,4,9}
sys=[];
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
function [sys,x0,str,ts]=mdlInitializeSizes(G,k)
sizes = simsizes;
sizes.NumContStates = 0;
sizes.NumDiscStates = 0;
sizes.NumOutputs =-1;
sizes.NumInputs =-1;
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 1;
sys = simsizes(sizes);
x0 = [];
str = [];
ts = [-1 0];
function sys=mdlOutputs(t,x,u,G,k)
if rem(length(u),k)~=0
u=[u,zeros(1,k-rem(length(u),k))];
end
l=length(u)/k;
L=size(G,2)/k;
n=size(G,1);
u1=[];
for i=1:L-1
u2=[u(i*k:-1:1),zeros(1,(L-i)*k)];
u1=[u1,u2];
end
for i=0:l-L
u3=[u((i+L)*k:-1:i*k+1)];
u1=[u1,u3];
end
for i=1:L-1
u4=[zeros(1,i*k),u(l*k:-1:(l-L+i)*k+1)];
u1=[u1,u4];
end
uu=reshape(u1,k*L,L+l-1);
sys=reshape(rem(G*uu,2),1,n*(L+l-1));
输入输出都是一维的向量(数据流),但输出的位数比输入多.实现的是编码功能. |