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
No comments:
Post a Comment