-
2 Программирование меню в среде guide
Программа подфункций для обработки событий пунктов меню представлена на рисунке 4.
function varargout = exxmenu1(varargin)
% EXXMENU1 M-file for exxmenu1.fig
% EXXMENU1, by itself, creates a new EXXMENU1 or raises the existing
% singleton*.
%
% H = EXXMENU1 returns the handle to a new EXXMENU1 or the handle to
% the existing singleton*.
%
% EXXMENU1('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in EXXMENU1.M with the given input arguments.
%
% EXXMENU1('Property','Value',...) creates a new EXXMENU1 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before exxmenu1_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to exxmenu1_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help exxmenu1
% Last Modified by GUIDE v2.5 17-Nov-2011 11:53:27
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @exxmenu1_OpeningFcn, ...
'gui_OutputFcn', @exxmenu1_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before exxmenu1 is made visible.
function exxmenu1_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to exxmenu1 (see VARARGIN)
% Choose default command line output for exxmenu1
handles.output = hObject;
Рисунок 4 - Программа подфункций для обработки событий пунктов меню
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes exxmenu1 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = exxmenu1_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --------------------------------------------------------------------
function mnFile_Callback(hObject, eventdata, handles)
% hObject handle to mnFile (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function mnFile_OpenPlot_Callback(hObject, eventdata, handles)
[FName,PName]=uigetfile('*.txt');
% проверяем, был ли выбран файл
if ~isequal(FName,0)
% пользователь выбрал файл, формируем его полное имя Name, сцепляя путь с именем.
Name=strcat(PName,FName);
% считываем данные и записываем их в вектора x и y
A=load(Name);
x=A(:,1);
y=A(:,2);
% делаем текущими оси с тэгом axes1, указатель на них в handles.axes1
axes(handles.axes1)
% строим график маркерами
plot(x,y,'o')
% получаем состояние флага у пункта XGrid меню Grid
xGridState=get(handles.mnGrid_XGrid,'Checked');
% если он установлен, то делаем сетку по x
if isequal(xGridState,'on')
set(handles.axes1,'XGrid','on')
end
% получаем состояние флага у пункта YGrid меню Grid
yGridState=get(handles.mnGrid_YGrid,'Checked');
% если он установлен, то делаем сетку по y
if isequal(yGridState,'on')
set(handles.axes1,'YGrid','on')
end
end
% hObject handle to mnFile_OpenPlot (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function mnFile_Exit_Callback(hObject, eventdata, handles)
% удаляем графическое окно, его тэг figure1, а указатель на него в handles.figure1
delete(handles.figure1)
Рисунок 4 - продолжение
% hObject handle to mnFile_Exit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function mnGrid_Callback(hObject, eventdata, handles)
% hObject handle to mnGrid (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function mnGrid_XGrid_Callback(hObject, eventdata, handles)
% проверяем текущее состояние флага у пункта XGrid
xGridState=get(hObject,'Checked');
if isequal(xGridState,'off')
% флаг был сброшен, но пользователь выбрал пункт XGrid
% добавляем сетку по оси x
set(handles.axes1,'XGrid','on')
% устанавливаем флаг
set(hObject,'Checked','on')
else
% флаг был установлен, но пользователь выбрал пункт XGrid
% убираем сетку по оси x
set(handles.axes1,'XGrid','off')
% сбрасываем флаг
set(hObject,'Checked','off')
end
% hObject handle to mnGrid_XGrid (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function mnGrid_YGrid_Callback(hObject, eventdata, handles)
% обработка события Callback пункта YGrid меню Grid
% проверяем текущее состояние флага у пункта YGrid
yGridState=get(hObject,'Checked');
if isequal(yGridState,'off')
% флаг был сброшен, но пользователь выбрал пункт YGrid
% добавляем сетку по оси y
set(handles.axes1,'YGrid','on')
% устанавливаем флаг
set(hObject,'Checked','on')
else
% флаг был установлен, но пользователь выбрал пункт YGrid
% убираем сетку по оси y
set(handles.axes1,'YGrid','off')
% сбрасываем флаг
set(hObject,'Checked','off')
end
% hObject handle to mnGrid_YGrid (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Рисунок 4 - продолжение