前几日浩子说要编一个基于Matlab的用户图像界面,他用GUIDE搭了一个大概的框架,大概要实现数据读入、做图分析、图像清除、关闭界面的功能,我用函数形式给改编了一个,虽然问题比较简单,但是也可以视为Gui设计的一个比较典型的问题,其实用Matlab编界面很简单,只是一个可视化的东西,真正的东西还是里面的程序。
%
%
%
%function:基于Matlab的Gui用户图形界面
clc;
clear all;
close all;
delete(findall(0,'type','figure')); %删除所有图像文件
clf reset;
H_figure=figure(1);
set(0,'showHiddenHandles','on');
set(gcf,'unit','normalized'); %位置和坐标轴
set(gcf,'defaultuicontrolunits','normalized');
set(gcf,'defaultuicontrolfontsize
set(gcf,'defaultuicontrolfontname
set(gcf,'defaultuicontrolhorizont
set(gcf,'menubar','none');
str='基于Matlab的用户图形界面设计';
set(gcf,'name',str,'numbertitle','off');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%以上进行系统参数的设置
h_help=uimenu(H_figure,'label','&Help');
h_help_sub1=uimenu(h_help,'label','Author','callback','author','tag','h_sub_1');
h_help_sub2=uimenu(h_help,'label','About','callback','about','tag','h_sub_2');
h_color=uimenu(H_figure,'label','&Color');
h_color_sub1=uimenu(h_color,'label','White','callback','set(h_axes_1,''color'',''white''),set(h_axes_2,''color'',''white''),set(h_color_sub1,''checked'',''on''),set(h_color_sub2,''checked'',''off'')');
h_color_sub2=uimenu(h_color,'label','Yellow','callback','set(h_axes_1,''color'',''yellow''),set(h_axes_2,''color'',''yellow''),set(h_color_sub2,''checked'',''on''),set(h_color_sub1,''checked'',''off'')');
h_grid=uimenu(H_figure,'label','&Grid');
h_grid_sub1=uimenu(h_grid,'label','Grid on','callback','grid(h_axes_1,''on''),grid(h_axes_2,''on''),set(h_grid_sub1,''checked'',''on''),set(h_grid_sub2,''checked'',''off'')');
h_grid_sub2=uimenu(h_grid,'label','Gridoff','callback','grid(h_axes_1,''off''),grid(h_axes_2,''off''),set(h_grid_sub1,''checked'',''off''),set(h_grid_sub2,''checked'',''on'')');
%%%%%%%%%%%%%%%%%%%%%%%%% 以上为菜单的基本建立过程设置 %%%%%%%%%%%%%%%%%%%%%
h_text_1=uicontrol(H_figure,'style','text','string','Automation Department of Njust','position',[0.13 0.93 0.75 0.08],'tag','text_1','fontsize',20,'fontname','newtimes','BackgroundColor',[0.8 0.8 0.8]);
h_axes_1=axes('position',[0.10,0.58,0.6,0.3],'visible','on','tag','axes_1');%建立绘图区域
set(gca,'xtick',[],'ytick',[]);
h_text_2=uicontrol(H_figure,'style','text','string','无连线曲线','position',[0.33 0.88 0.18 0.05],'tag','text_2','fontsize',12,'BackgroundColor',[0.8 0.8 0.8]);
h_axes_2=axes('position',[0.10,0.18,0.6,0.3],'visible','on','tag','axes_2');%建立绘图区域
set(gca,'xtick',[],'ytick',[]);
h_text_3=uicontrol(H_figure,'style','text','string','有连线曲线','position',[0.33 0.48 0.18 0.05],'tag','text_2','fontsize',12,'BackgroundColor',[0.8 0.8 0.8]);
%%%%%%%%%%%%%%%%%%%%%%%%% 以上为图形的模块化的基本设置 %%%%%%%%%%%%%%%%%%%%%
h_text_4=uicontrol(H_figure,'style','text','string','信息显示如右:','position',[0.05 0.05 0.35 0.08],'tag','text_4','BackgroundColor',[0.8 0.8 0.8]);
h_text_5=uicontrol(H_figure,'style','text','string','','position',[0.40 0.05 0.35 0.08],'tag','text_5','BackgroundColor',[0.8 0.8 0.8]);
h_pushbutton_1=uicontrol(H_figure,'style','pushbutton','string','导入数据','position',[0.75,0.78,0.23,0.10],'tag','pushbutton_1','callback','plot_rawdata','BackgroundColor',[0.8 0.8 0.8]);
h_pushbutton_2=uicontrol(H_figure,'style','pushbutton','string','连线处理','position',[0.75,0.45,0.23,0.10],'tag','pushbutton_2','callback','plot_process','BackgroundColor',[0.8 0.8 0.8]);
h_listbox_1=uicontrol(H_figure,'style','popupmenu','string','无次序|有次序','position',[0.75 0.60 0.22 0.06],'tag','AlgrithmType','fontsize',12,'BackgroundColor',[0.8 0.8 0.8]);
h_text_6=uicontrol(H_figure,'style','text','string','选择连线类型','position',[0.75 0.66 0.32 0.08],'tag','text_6','BackgroundColor',[0.8 0.8 0.8],'fontsize',15);
h_pushbutton_3=uicontrol(H_figure,'style','pushbutton','string','清除图像','position',[0.75,0.29,0.23,0.10],'tag','pushbutton_3','callback','Reset','BackgroundColor',[0.8 0.8 0.8]);
h_pushbutton_4=uicontrol(H_figure,'style','pushbutton','string','关闭界面','position',[0.75,0.12,0.23,0.10],'tag','pushbutton_4','callback','close all','BackgroundColor',[0.8 0.8 0.8]);
图2 作者信息
msgbox({'单位:Njust 1002教研室', 'Email:dingqian12345@126.com','Name:DingQian'},'作者信息','help')
h1=findobj('tag','h_sub_1');
h2=findobj('tag','h_sub_2');
set(h1,'checked','on');
set(h2,'checked','off');
图3 选择文件界面
图4 连线处理点击后界面
参考文献
[1]
[2] 神经元房室数据做图[EB/OL].http://blog.sina.com.cn/s/blog_4b013fb10100l28h.html.[2010-10-28].
2010年10月28日晚上于njust 10系 310房间
CopyRight:版权所有若需转载或使用请联系作者
Email:dingqian12345@126.com