How do I create a button that switches to another tab of a GUI?
조회 수: 24 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
답변 (1개)
Sreelakshmi S.B
2019년 3월 8일
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!