如何在matlab中调用主GUI上的其他面板
How to call other panels on main GUI in matlab
This image is my plan that have panel1 panel2 and panel3
当点击panel1上的'next'按钮时,我会显示panel2。如何创建下一个按钮?请帮帮我。谢谢。
This is my code that I use guide in matlab.
function varargout = testFig(varargin)
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @testFig_OpeningFcn, ...
'gui_OutputFcn', @testFig_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 testFig is made visible.
function testFig_OpeningFcn(hObject, eventdata, handles, varargin)
% Update handles structure
guidata(hObject, handles);
% --- Outputs from this function are returned to the command line.
function varargout = testFig_OutputFcn(hObject, eventdata, handles)
Panel1
% --- Browse video files.
function video_Callback(hObject, eventdata, handles)
% hObject handle to video (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
FileName = uigetfile('*.avi','Select the avi file');
v = VideoReader(FileName);
video = readFrame(v);
imshow(video, 'Parent', handles.axes1);
% --- Browse image files.
function image_Callback(hObject, eventdata, handles)
% hObject handle to image (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[FileName PathName] = uigetfile('*.jpg','Select the jpg file');
Image = imread([PathName FileName]);
imshow(Image, 'Parent', handles.axes1);
% --- 'next' button in panel1.
function next1_Callback(hObject, eventdata, handles)
% hObject handle to next1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
disp(next2_Callback);
Panel2
% --- 'next' button in panel2.
function next2_Callback(hObject, eventdata, handles)
% hObject handle to next2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- 'back' button in panel2.
function back2_Callback(hObject, eventdata, handles)
% hObject handle to back2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- 'detect' button in panel3.
function detect_Callback(hObject, eventdata, handles)
% hObject handle to detect (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of detect
% --- 'regiongrowing' button in panel3.
function regiongrowing_Callback(hObject, eventdata, handles)
% hObject handle to regiongrowing (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of regiongrowing
Panel3
% --- 'back' button in panel3.
function back3_Callback(hObject, eventdata, handles)
% hObject handle to back3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- 'home' button in panel3.
function home_Callback(hObject, eventdata, handles)
% hObject handle to home (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- 'finish' button in panel3.
function pushbutton8finish_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton8finish (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
您可以通过在按钮回调中设置面板的 Visibility
属性来完成此操作。假设您已使用 GUIDE 中的 属性 Inspector 将 uipanel2 的 Visiblity
初始化为 Off
,您可以为 uipanel1 的下一个按钮
定义回调
% --- 'next' button in panel1.
function next1_Callback(hObject, eventdata, handles)
% hObject handle to next1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.uipanel2, 'Visible', 'On')
同样,后退按钮可以设置Visible
到Off
。
This image is my plan that have panel1 panel2 and panel3
当点击panel1上的'next'按钮时,我会显示panel2。如何创建下一个按钮?请帮帮我。谢谢。
This is my code that I use guide in matlab.
function varargout = testFig(varargin)
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @testFig_OpeningFcn, ...
'gui_OutputFcn', @testFig_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 testFig is made visible.
function testFig_OpeningFcn(hObject, eventdata, handles, varargin)
% Update handles structure
guidata(hObject, handles);
% --- Outputs from this function are returned to the command line.
function varargout = testFig_OutputFcn(hObject, eventdata, handles)
Panel1
% --- Browse video files.
function video_Callback(hObject, eventdata, handles)
% hObject handle to video (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
FileName = uigetfile('*.avi','Select the avi file');
v = VideoReader(FileName);
video = readFrame(v);
imshow(video, 'Parent', handles.axes1);
% --- Browse image files.
function image_Callback(hObject, eventdata, handles)
% hObject handle to image (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[FileName PathName] = uigetfile('*.jpg','Select the jpg file');
Image = imread([PathName FileName]);
imshow(Image, 'Parent', handles.axes1);
% --- 'next' button in panel1.
function next1_Callback(hObject, eventdata, handles)
% hObject handle to next1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
disp(next2_Callback);
Panel2
% --- 'next' button in panel2.
function next2_Callback(hObject, eventdata, handles)
% hObject handle to next2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- 'back' button in panel2.
function back2_Callback(hObject, eventdata, handles)
% hObject handle to back2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- 'detect' button in panel3.
function detect_Callback(hObject, eventdata, handles)
% hObject handle to detect (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of detect
% --- 'regiongrowing' button in panel3.
function regiongrowing_Callback(hObject, eventdata, handles)
% hObject handle to regiongrowing (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of regiongrowing
Panel3
% --- 'back' button in panel3.
function back3_Callback(hObject, eventdata, handles)
% hObject handle to back3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- 'home' button in panel3.
function home_Callback(hObject, eventdata, handles)
% hObject handle to home (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- 'finish' button in panel3.
function pushbutton8finish_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton8finish (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
您可以通过在按钮回调中设置面板的 Visibility
属性来完成此操作。假设您已使用 GUIDE 中的 属性 Inspector 将 uipanel2 的 Visiblity
初始化为 Off
,您可以为 uipanel1 的下一个按钮
% --- 'next' button in panel1.
function next1_Callback(hObject, eventdata, handles)
% hObject handle to next1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.uipanel2, 'Visible', 'On')
同样,后退按钮可以设置Visible
到Off
。