[求助]怎样给这个matlab程序加注释?
这里有两段matlab程序,麻烦各位帮我注释一下,老师要考的,谢谢。(希望能写一下哪里实现的什么功能。)这是用matlab实现伪随机序列的程序。谢谢各位XDJM.
第一段
function [sys,x0,str,ts]=pnsequence(t,x,u,flag,poly,period,ini_st)
switch flag
case 0,
[sys,x0,str,ts]=mdlInitializeSizes(poly,period,ini_st);
case 2,
sys=mdlUpdate(t,x,u,poly);
case 3,
sys=mdlOutputs(t,x,u);
case { 1, 4, 9 },
sys=[];
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
%end sfuntmp1
%mdlInitializeSizes
function [sys,x0,str,ts] = mdlInitializeSizes(poly,period,ini_st)
n_dis=length(poly);
sizes = simsizes;
sizes.NumContStates = 0;
sizes.NumDiscStates = n_dis;
sizes.NumOutputs = 1;
sizes.NumInputs = 0;
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 1;
sys = simsizes(sizes);
x0 = [ini_st];
str =[];
ts = [period 0];
%end mdlInitializeSizes
%mdlUpdate
function sys = mdlUpdate(t,x,u,poly)
reg=x;
n_x=length(x);
temp=mod(poly*reg(1:n_x-1),2);
%完成异或
reg=[reg(2:n_x);temp];
%进行左移位
sys=reg;
%end mdlUpdate
%mdlOutputs
function sys=mdlOutputs(t,x,u)
sys=x(1);
%end mdlOutputs
第二段
function [sys,x0,str,ts] = weisui1(t,x,u,flag)
switch flag,
case 0
[sys,x0,str,ts]=mdlInitializeSizes;
case 3
sys=mdlOutputs(t,x,u);
case { 1, 2, 4, 9 }
sys=[];
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
function [sys,x0,str,ts] = mdlInitializeSizes()
sizes = simsizes;
sizes.NumContStates = 0;
sizes.NumDiscStates = 0;
sizes.NumOutputs = -1; % dynamically sized
sizes.NumInputs = -1; % dynamically sized
sizes.DirFeedthrough = 1; % has direct feedthrough
sizes.NumSampleTimes = 1;
sys = simsizes(sizes);
str = [];
x0 = [];
ts = [-1 0]; % inherited sample time
function sys = mdlOutputs(t,x,u)
sys = ceil(rand(1)*32);
% end mdlOutputs
拜托拜托!![em04]