如何在matlab中调用主GUI上的其他面板

时间:2016-02-19 08:23:57

标签: matlab matlab-guide

This image is my plan that have panel1 panel2 and panel3

This image is show panel1

点击panel1上的“下一步”按钮时,我会显示panel2。如何创建下一个按钮?请帮帮我。谢谢。

  

这是我在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)

1 个答案:

答案 0 :(得分:1)

您可以通过在按钮回调中设置面板的Visibility属性来完成此操作。假设您已使用GUIDE中的Property Inspector初始化了uipanel2的VisiblityOff,您可以为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