How do I create a button that switches to another tab of a GUI?

28 Ansichten (letzte 30 Tage)
Avin Wijayaweera
Avin Wijayaweera am 5 Mär. 2019
Beantwortet: Sreelakshmi S.B am 8 Mär. 2019
Here is my current code:
fig = uifigure('Name', 'Diabetes Diagnosis');
tabGroup = uitabgroup(fig);
sympTab = uitab(tabGroup,'Title','Symptoms');
famHistTab = uitab(tabGroup,'Title', 'Family History');
nextCtrl = uicontrol(sympTab, 'ButtonPushedFcn', {@buttonPushed,tabGroup,famHistTab});
function buttonPushed(uiTabGroup, uiFamHistTab)
uiTabGroup.SelectedTab = uiFamHistTab
end
The control is meant to switch from sympTab to famHistTab. I think the biggest problem is that I don't have any idea how to format a callback function. It outputs a figure, but the button doesn't have any apparent effect.

Antworten (1)

Sreelakshmi S.B
Sreelakshmi S.B am 8 Mär. 2019
You can try the code below. I’ve used uibutton in place of uicontrol since there is no 'ButtonPushedFcn' property on the UIControl class.
As for callback, assign a function handle that references the callback function to the ButtonDownFcn property of the button and mention the arguments you're passing when doing this,as shown below:
fig = uifigure('Name', 'Diabetes Diagnosis');
tabGroup = uitabgroup(fig);
sympTab = uitab(tabGroup,'Title','Symptoms');
famHistTab = uitab(tabGroup,'Title', 'Family History');
btn = uibutton(sympTab,'ButtonPushedFcn', @(arg1,arg2) buttonPushed(tabGroup,famHistTab));
% Create the function for the ButtonPushedFcn callback
function buttonPushed(uitabGroup,uiFamHistTab)
uitabGroup.SelectedTab = uiFamHistTab;
end

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by