function my_callback_fcn(handles)
global Type
global Fs
global N
global x
Fs=44100;
dt=1/Fs;
T=2;
N=T/dt;
t=linspace(0,T,N);
s1=get(handles.edit1,‘string’);
F=str2double(s1);
s1=get(handles.edit2,‘string’);
A=str2double(s1);
if Type1
x=0.5Arandn(1,N);
end
if Type2
x=Asin(2piFt);
end
if Type3
x=Asquare(2piFt);
end
if Type4
x=Asawtooth(2piFt);
end
plot(handles.axes1,t,x,‘b’,‘linewidth’,2);
axis(handles.axes1,[0,0.01,-1,1]);
grid(handles.axes1);
调用函数
global Type
Type=2;my_callback_fcn(handles);
定时器
timer
matlab中使用定时器(timer)基本格式为
t = timer(‘PropertyName1’, PropertyValue1, ‘PropertyName2’, PropertyValue2,…);
start(t);
最简单的定时器一般指定以下属性:
TimerFcn ——指定定时器被触发时要执行的函数或语句
Period ——指定定时器的触发时间,单位为秒
ExecutionMode ——指定定时器的触发方式(触发一次,还是循环触发……),该属性有四个可选值,具体见matlab帮助
TasksToExecute ——指定定时器最多被触发的次数,该属性默认为inf,如果希望不停的循环执行,可以不指定该属性
tag ——一个字符串,可以任意指定,一般用于标志某个特定的定时器,以方便在程序中别的地方查找该定时器