Showing posts with label TAB. Show all posts
Showing posts with label TAB. Show all posts

Monday, July 10, 2017

[Matlab GUI] Uitab and ButtonDownFcn

Using 'ButtonDownFcn', advanced functions can be implemented in MATLAB GUIDE.

For example, depending on the tab selected by clicking, strings displayed on the buttons can be changed. See the example below.

1. Place the code below into the XXX_OpeningFcn
--------------------------------
% Suppress an annoying warning message
warning off MATLAB:uitabgroup:OldVersion

%---- Create a tab group
handles.tgroup = uitabgroup('Parent',handles.mainGui,'TabLocation','top');
% Set position [left, bottom, width, height], normalized unit
set(handles.tgroup,'Units','Normalized','Position',[0 0 1 0.945]);
% Create each tab
handles.maintab = uitab('Parent',handles.tgroup,'Title','  Main  ',...
    'ButtonDownFcn',@tabmain);
handles.doetab = uitab('Parent',handles.tgroup,'Title','  DoE   ',...
    'ButtonDownFcn',@tabdoe);
handles.simulinktab = uitab('Parent',handles.tgroup,'Title','Simulink',...
    'ButtonDownFcn',@tabsimulink);
% Place panels into each tab
set(handles.Tab1,'Parent',handles.maintab);
set(handles.Tab2,'Parent',handles.doetab);
set(handles.Tab3,'Parent',handles.simulinktab);

% Reposition each panel to the same location as Tab1
set(handles.Tab2,'Position',get(handles.Tab1,'Position'));
set(handles.Tab3,'Position',get(handles.Tab1,'Position'));
--------------------------------------------------------------------------------

2. Create functions tabmain, tabdoe, and tabsimulink
One of three functions could be created as below.

-----------------------------------
% When clicking the tab 'DoE '
function tabdoe(hObject,~,~)
 
handles = guidata(hObject);
% Enable buttons
set(handles.Run,'Enable','on');
set(handles.ImportAll,'Enable','on');
set(handles.ExportAll,'Enable','on');
% Set button string
set(handles.Run,'String','Run(D)');
set(handles.ImportAll,'String','Load');
set(handles.ExportAll,'String','Save');

guidata(hObject,handles);
-----------------------------------------



Related Post
1. Create tabs using uitab and uitabgroup

Sunday, March 12, 2017

[Matlab GUI] Create the tab UI using GUIDE

This example shows how to create tab.

M script
----------------------------------------------------------------
% Prepare a tab-group consisting of two tabs
hTabGroup = uitabgroup; drawnow;
% Define tab position
% Set(hTabGroup,'Position',[.1 .2 .5 .3]);
set(hTabGroup,'Position',[.1 .2 .8 .5]);

% Set two tabs "Panel 1" and "Panel 2" as child 
tab1 = uitab(hTabGroup, 'title','Panel 1');
a = axes('parent', tab1); surf(peaks);
tab2 = uitab(hTabGroup, 'title','Panel 2');
uicontrol(tab2, 'String','Close', 'Callback','close(gcbf)');
h2=uitabgroup('parent',tab2); %drawnow;

% Set the tab "Panel 2" as parent
set(h2,'Position',[.2 .3 .3 .2]);
% Set two tabs "t1" and "t2" as child of "Panel 2"
t1 = uitab(h2,'title','t1');
t2 = uitab(h2,'title','t2');
----------------------------------------------------------------

Download "guide_tab.fig" and "guide_tab.m"