kwaakwang
kwaakwang

Reputation: 34

How to call other panels on main GUI in matlab

This image is my plan that have panel1 panel2 and panel3

This image is show panel1

I will show panel2 when click 'next' button on panel1. How to create next button? help me please. Thank you.

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)

Upvotes: 0

Views: 57

Answers (1)

logan rakai
logan rakai

Reputation: 2557

You can accomplish this by setting the Visibility properties of the panels in the button callbacks. Assuming you have initialized the Visiblity to Off for uipanel2 by using the Property Inspector in GUIDE you can define the callback for uipanel1's next button

% --- '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')

Similarly, the back buttons can set Visible to Off.

Upvotes: 1

Related Questions