📄 mathgui.m
字号:
function mathgui(mode)
%MATHGUI Graphical User Interface program for special math functions.
% ADSP Toolbox: Version 2.0
% For use with "Analog and Digital Signal Processing", 2nd Ed.
% Published by PWS Publishing Co.
%
% Ashok Ambardar, EE Dept. MTU, Houghton, MI 49931, USA
% http://www.ee.mtu/faculty/akambard.html
% e-mail: akambard@mtu.edu
% Copyright (c) 1998
v=matverch;
if v<5,
errordlg('This gui requires MATLAB 5.x and above','Version Error');
return,
end
if nargin == 0, mode = 0; end
if mode ~= 0,
f = gcf;
ui = get(f,'userdata');
math_edt = ui(3);
autoplot = ui(12);
plt_btn = ui(13);
n_val = ui(5);
m_val = ui(11);
x_val = ui(7);
curs_btn = ui(18);
curs_dsp = ui(14:17);
end
if mode == 0,
grey = [0.5,0.5,0.5];
ltgrey = grey*1.5;
dkgrey = grey*0.5;
scrn_size = get(0,'screensize');
fig_w = 620;
fig_h = 450;
flft = (scrn_size(3) - fig_w)/2;
fbtm = (scrn_size(4) - fig_h)/2;
ver_str = version;
ver4 = length(findstr('4.',ver_str));
if ver4,
int_str = 'yes';
f = figure('pos',[flft,fbtm,fig_w,fig_h],'menubar','none',...
'name','Special Math Functions','numbertitle','off',...
'resize','off','vis','off','interruptible',int_str,...
'color',dkgrey,'defaultaxesfontsize',10,...
'defaulttextfontsize',10);
else
int_str = 'on';
eval('f = colordef(''new'',''none'');');
set(f,'pos',[flft,fbtm,fig_w,fig_h],'menubar','none',...
'name','Special Math Functions','numbertitle','off',...
'resize','off','vis','off','interruptible',int_str,...
'color',dkgrey,'defaultaxesfontsize',8,...
'defaultuicontrolback',[0.5,0.5,0.5],...
'defaulttextfontsize',8);
end
%%% OPTIONS:%%%%%%%
uim(1) = uimenu('label','OPTIONS');
uim(2) = uimenu(uim(1),'label','Help and Info','callback','mathhlp');
uim(3) = uimenu(uim(1),'label','Export Data','separator','on',...
'callback','mathgui(15)');
uim(4) = uimenu(uim(1),'label','Print Figure','separator','on',...
'callback','printdlg(gcf)');
uim(5) = uimenu(uim(1),'label','Close and Exit','separator','on',...
'callback','close(gcf)');
uim(6) = uimenu('label',' Axis Limits','separator','on',...
'callback','mathgui(17)');
uim(7) = uimenu('label',' Zoom ON','separator','on',...
'callback','mathgui(18)');
uim(8) = uimenu('label',' Zoom OFF','separator','on',...
'callback','mathgui(19)');
%%%%%%%%%
lft = 10; btm = fig_h - 5;btm1 = 35; btm2 = 10;
ui(1) = uicontrol('style','frame','pos',[5,btm-127,175,119],...
'back',grey,'fore',ltgrey);
btm = btm - 33;
ui(2) = uicontrol('style','text','pos',[lft,btm,165,17],...
'string','Function','back',ltgrey,'fore','c','horiz','left');
btm = btm - 22;
ui(3) = uicontrol('style','popup','pos',[lft,btm,165,17],...
'string',['Sine Integral|Fresnel Int 1st|',...
'Fresnel Int 2nd|Chebyshev|Chebyshev 2nd Kind|Bessel J|',...
'Spherical Bessel j'],...
'back','w','callback','mathgui(1)');
btm = btm - 22;
ui(8) = uicontrol('style','text','pos',[lft,btm,60,17],...
'string','Form','back',ltgrey,'horiz','right');
ui(9) = uicontrol('style','text','pos',[lft+65,btm,100,17],...
'string','si(x)','back','w');
btm = btm - 22;
ui(4) = uicontrol('style','text','pos',[lft,btm,60,17],...
'string','n value(s)','horiz','right','vis','off');
ui(5) = uicontrol('style','edit','pos',[lft+65,btm,100,18],...
'string','1,2,3','back','w','callback','mathgui(2)','vis','off');
btm = btm - 22;
ui(10) = uicontrol('style','text','pos',[lft,btm,60,17],...
'string','m value','horiz','right','vis','off');
ui(11) = uicontrol('style','edit','pos',[lft+65,btm,100,18],...
'string','1','back','w','callback','mathgui(2)','vis','off');
uicontrol('style','frame','pos',[5,btm-40,175,27],...
'back',grey,'fore',ltgrey);
btm = btm - 35;
ui(6) = uicontrol('style','text','pos',[lft,btm,70,17],...
'string','x range','horiz','right','userdata',0);
ui(7) = uicontrol('style','edit','pos',[lft+75,btm,90,18],...
'string','-5,5','back','w','callback','mathgui(2)');
btm = btm - 35;
ui(26) = uicontrol('style','text','pos',[lft,btm,70,17],...
'string','# of points','horiz','right');
ui(27) = uicontrol('style','edit','pos',[lft+75,btm,90,18],...
'string','200','back','w','callback','mathgui(2)');
uicontrol('style','frame','pos',[5,btm-40,175,27],...
'back',grey,'fore',ltgrey);
btm = btm - 35;
ui(12) = uicontrol('style','check','pos',[lft,btm,80,17],...
'string','AutoPlot','value',0,'fore','c','callback','mathgui(3)');
ui(13) = uicontrol('style','push','pos',[lft+95,btm-2,70,20],...
'string','Plot','callback','mathplt');
btm = btm -32;
ui(18) = uicontrol('style','check','pos',[lft+95,btm,70,20],...
'string','Cursor','back','y','callback','mathgui(4)');
pos = get(f,'pos');
lef = pos(3)-166;
bot = pos(4)-21;
ui(14) = uicontrol('style','text','pos',[lef,bot,20,20],...
'string','X ','horiz','right');
ui(15) = uicontrol('style','text','pos',[lef+20,bot,60,20],...
'string','','back','w');
ui(16) = uicontrol('style','text','pos',[lef+85,bot,20,20],...
'string','Y ','horiz','right');
ui(17) = uicontrol('style','text','pos',[lef+105,bot,60,20],...
'string','','back','w');
set(ui(14:17),'vis','off');
ui(20) = axes('units','pixel','pos',[210,50,390,350],'box','on',...
'xlim',[0,1],'color','k',...
'xgrid','on','ygrid','on');
title('Function Plot');
xlabel('Variable x')
set(f,'userdata',ui);
set(ui(1),'userdata',ui(10));
mathplt;
drawnow;
set(f,'vis','on');
elseif mode == 1, % set values for math functions
val = get(ui(3),'value');
if val<4
set(ui([4:5,10:11]),'vis','off');
else
set(ui(4:5),'vis','on');
set(ui(10:11),'vis','off');
end
if val == 1 %sine int
set(ui(9),'string', 'si(x)');
elseif val == 2 %Fresnel s
set(ui(9),'string', 'S(x)');
elseif val == 3 %Fresnel c
set(ui(9),'string', 'C(x)');
elseif val == 4 %Cheby1
set(ui(9),'string', 'T(n,x)');
elseif val == 5 %Cheby2
set(ui(9),'string', 'U(n,x)');
elseif val == 6 %Besj
set(ui(9),'string', 'J(n,x)');
elseif val == 7 %Besjnu
set(ui(9),'string', 'j(n,x)');
end
if get(autoplot,'value'),mathplt,end
elseif mode == 2, % edit values for math functions
if get(autoplot,'value'),mathplt,end
elseif mode == 3, % autoplot
if get(autoplot,'value'),
set(plt_btn,'enable','off');
mathplt
else
set(plt_btn,'enable','on');
end
elseif mode == 4, % cursor
if get(curs_btn,'value')
set(curs_dsp,'vis','on');
set(f,'WindowButtonMotionFcn','mathgui(5)',...
'WindowButtonDownFcn','mathgui(5)');
else
set(f,'Pointer','arrow','WindowButtonMotionFcn','','WindowButtonDownFcn','')
set(curs_dsp,'vis','off')
set(curs_btn,'value',0),
end
elseif mode == 5, % cursor movement
h=gca;
set(f,'currentaxes',h);
lim=get(h,'pos'); % get current axis position
c_p = [lim(1) lim(1)+lim(3) lim(2) lim(2)+lim(4)];
f_p=get(f,'CurrentPoint'); % get co-ordinates of current point
if f_p(1) < c_p(1) | f_p(1) > c_p(2) | f_p(2) < c_p(3) | f_p(2) > c_p(4)
set(f,'Pointer','arrow');
set(curs_dsp(2),'string','');
set(curs_dsp(4),'string','');
else
curr_pt=get(h,'CurrentPoint'); % get current mouse position
set(f,'Pointer','crosshair');
set(curs_dsp(2),'string',num2str(curr_pt(1,1)));
set(curs_dsp(4),'string',num2str(curr_pt(1,2)));
end
elseif mode == 15, %Export data
mathplt;
fstr=get(ui(9),'string');fval=get(ui(3),'value');%fstr=fstr(fval,:); %Hz
str1=['Export values of ' fstr ' as'];
str2='Export values of variable x as';
str3='Export values of n as';
if fval>3,
exp_str={str1,str2,str3};
exp_var={'funval','funvar','nval'};
else
exp_str={str1,str2};
exp_var={'funval','funvar'};
end
expect=inputdlg(exp_str,'Save Variables as',1,exp_var);
if ~isempty(expect)
fv=get(ui(14),'userdata');%%% FIX FOR UIs
xv=get(ui(15),'userdata');%%% FIX FOR UIs
nv=get(ui(16),'userdata');
if ~isempty(expect{1}),assignin('base',expect{1},fv);end
if ~isempty(expect{2}),assignin('base',expect{2},xv);end
if fval>3
if ~isempty(expect{3}),assignin('base',expect{3},nv);end
end
end
elseif mode == 16, % Axis Control Help
msgbox(['Turn Cursor off. Click in a plot window. ',...
' Then, come back and click on Execute'],...
'Axis Control Info','help')
elseif mode == 17, % Axis Control
cur_axs=[]; cur_obj = gco;
cur_par = get(cur_obj,'parent');
if ~isempty(cur_par)
if cur_par == f,
cur_axs = cur_obj;
else
cur_axs = cur_par;
end
end
if isempty(cur_axs),mathgui(16);
else
set(curs_btn,'value',0);
mathgui(4); %%% REPLACE number BY CURSOR MODE
if any(cur_axs==ui([20])),%%%% CHANGE UI numbers
val=get(ui(3),'value');
if val==1,txt='Sine integral';%%%% CHANGE UI numbers
elseif val==2,txt='Fresnel int 1st kind';%%%% CHANGE UI numbers
elseif val==3,txt='Fresnel int 2nd kind';%%%% CHANGE UI numbers
elseif val==4,txt='Chebyshev function';%%%% CHANGE UI numbers
elseif val==5,txt='Chebyshev fcn 2nd kind';%%%% CHANGE UI numbers
elseif val==6,txt='Bessel function J';%%%% CHANGE UI numbers
elseif val==7,txt='Spherical Bess fcn j';%%%% CHANGE UI numbers
end
axlimdlg(txt,[1 1]); %[1 1]=auto +linear/log, [1 0]=auto, no linear/log
else
mathgui(16);
end
end
elseif mode == 18, % zoom on
set(curs_btn,'value',0);
mathgui(4); % Use CURSOR MODE
if get(ui(6),'userdata')==0 %%Change ui(15) to whatever
zoom on
set(ui(6),'userdata',1);
else
msgbox('Zoom is already ON.','Zoom Info','help')
end
elseif mode == 19, % zoom off
set(curs_btn,'value',0);
mathgui(4); % Use CURSOR MODE
if get(ui(6),'userdata')==1
%%%%%Insert old zoom off here
set(f,'currentaxes',ui(20));
zoom out,zoom reset,zoom off
set(ui(6),'userdata',0);
else
msgbox('Zoom is already OFF.','Zoom Info','help')
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -