登录论坛

查看完整版本 : 【求助】请帮忙调试一个程序


chuidiaoxianzhe
2008-01-14, 21:09
%循环卷积

H=axes('unit','normalized','position',[0,0,1,1],'visible','off');
set(gcf,'currentaxes',H);
str='\fontname{隶书}循环卷积动态演示';
text(0.32,0.97,str,'fontsize',13);
set(gcf,'unit','normalized','position',[0.1,0.2,0.5,0.5]);
set(gcf,'defaultuicontrolunits','normalized');

haxes1=axes('position',[0.10,0.05,0.63,0.18]);%position后面的矩阵四个数据分别表示组建的坐标位置的左边、底部、宽、高
%整个图形窗口的左下为(0,0),右上为(1,1)
haxes2=axes('position',[0.10,0.29,0.63,0.18]);
haxes3=axes('position',[0.10,0.53,0.63,0.18]);
haxes4=axes('position',[0.10,0.77,0.63,0.18]);

htext1=uicontrol(gcf,'style','text',...
'position',[0.01,0.88,0.08,0.06],...
'fontsize',13,...
'string','X(n)');
htext2=uicontrol(gcf,'style','text',...
'position',[0.01,0.64,0.08,0.06],...
'fontsize',12,...
'string','翻转移位');
htext3=uicontrol(gcf,'style','text',...
'position',[0.01,0.40,0.08,0.06],...
'fontsize',12,...
'string','移位求积');
htext4=uicontrol(gcf,'style','text',...
'position',[0.01,0.15,0.08,0.06],...
'fontsize',12,...
'string','线性卷积');
htext5=uicontrol(gcf,'style','text',...
'position',[0.75,0.85,0.22,0.10],...
'fontsize',10,...
'string','输入序列X1(n)=');
hedit1=uicontrol('style','edit',...
'position',[0.75,0.73,0.22,0.10],...
'backgroundcolor','white',...
'visible','on','CallBack',['x1=get(gcbo,''string'');',...
'x1=str2num(x1);']);
htext6=uicontrol(gcf,'style','text',...
'position',[0.75,0.60,0.22,0.10],...
'fontsize',10,...
'string','输入序列X2(n)=');
hedit2=uicontrol('style','edit',...
'position',[0.75,0.48,0.22,0.10],...
'backgroundcolor','white',...
'visible','on','CallBack',['x2=get(gcbo,''string'');',...
'x2=str2num(x2);']);
htext7=uicontrol(gcf,'style','text',...
'position',[0.75,0.35,0.22,0.10],...
'fontsize',10,...
'string','输入卷积长度N=');
hedit3=uicontrol('style','edit',...
'position',[0.75,0.23,0.22,0.10],...
'backgroundcolor','white',...
'visible','on','CallBack',['N=get(gcbo,''string'');',...
'N=str2num(N);']);
hcontrol2=uicontrol(gcf,'style','pushbutton',...
'position',[0.75,0.13,0.22,0.07],...
'fontsize',10,...
'string','开始');
hcontrol1=uicontrol(gcf,'style','pushbutton',...
'position',[0.75,0.05,0.22,0.07],...
'fontsize',10,...
'string','退出');
set(hcontrol2,'CallBack',['juan(haxes1,haxes2,haxes3,haxes4,x1,x2,N);']);
set(hcontrol1,'CallBack','close(gcf)');



下面是调用的juan函数。
% juan(haxes1,haxes2,haxes3,haxes4) 绘制图象
%function []=juan(haxes1,haxes2,haxes3,haxes4,x1,x2,N)
clear all;
figure(2);
x1=input('x1=');
x2=input('x2=');
N=input('N=');

haxes1=axes('position',[0.10,0.05,0.63,0.18]);
haxes2=axes('position',[0.10,0.29,0.63,0.18]);
haxes3=axes('position',[0.10,0.53,0.63,0.18]);
haxes4=axes('position',[0.10,0.77,0.63,0.18]);

lx1=length(x1);
lx2=length(x2);
nx=N-lx1; nh=N-lx2;

axes(haxes4);hold off
dt=1; % dt 运算时间间隔 ;
lt=N; % 取长者为补零长度基准
x=[x1,zeros(1,nx)];
t1=(1: N)*dt;
stem(t1,x,'.');
axis([-N,2*N,min(x),max(x)]), hold on;

for k=0: N-1
axes(haxes3);hold off
h=[x2,zeros(1,nh)];
hf(1:N)=fliplr(h); % 将 h 的左右翻转 , 记为 hf
y=zeros(1,N); % y 数组初始化
p=[hf(N-k: N),hf(1: N-k-1)]; % 使 hf 向右循环移位 ,hf(1: end-k)=hf(1:3*lt-k)
if k==0
stem(t1,hf,'.r');
axis([-lt*dt, 2*lt*dt, min(p), max(p)]);
pause
end
stem(t1,p,'.r')
axis([-lt*dt, 2*lt*dt, min(p), max(p)])

axes(haxes2);hold off
p=[hf(N-k: N),hf(1: N-k-1)]; % 使 hf 向右循环移位 ,hf(1: end-k)=hf(1:3*lt-k)
y1=x.*p*dt;
stem(t1,y1,'.r')

axes(haxes1);
p=[hf(N-k: N),hf(1: N-k-1)]; % 使 hf 向右循环移位 ,hf(1: end-k)=hf(1:3*lt-k)
y1=x.*p*dt; % 使输入和翻转移位的脉冲过渡函数逐项相乘 , 再乘 dt
yk=sum(y1); % 相加,等效于积分
y(k+1)=yk;
stem((k+1)*dt,yk,'.r')
hold on
pause(1)
end
hold on

运行后显示错误:
??? Attempt to execute SCRIPT juan as a function.

??? Error while evaluating uicontrol Callback.