Is there a way in enable and disable tabs in Matlab?

33 次查看(过去 30 天)
I've been trying to be able to enable and disable the ability to go into a tab depending on the value of a
app.NumberOfTabsDropDown.Value
I tried switch cases for the callback, but I get a test case where it's not valid
function TabGroupSelectionChanged(app,event)
selectedTab = app.TabGroup.SelectedTab;
numberOfTabs = app.NumberOfTabsDropDown.Value; % It can only select 1 to 4
% We don't need to check for Tab 1
switch selectedTab.Title
case 'Tab 2'
switch numberOfTabs
case '1'
app.TabGroup.SelectedTab = event.OldValue;
case '2'
return
case '3'
return
case '4'
return
end
case 'Tab 3'
switch numberOfTabs
case '1'
app.TabGroup.SelectedTab = event.OldValue;
case '2'
app.TabGroup.SelectedTab = event.OldValue;
case '3'
return
case '4'
return
end
case 'Tab 4'
switch numberOfTabs
case '1'
app.TabGroup.SelectedTab = event.OldValue;
case '2'
app.TabGroup.SelectedTab = event.OldValue;
case '3'
app.TabGroup.SelectedTab = event.OldValue;
case '4'
return
end
end
end
The code works, but there is a case if I change the app.NumberOfTabsDropDown.Value = 2 while I'm currently on 'Tab 4' and click on 'Tab 3', it goes back to 'Tab 4'. Is there a way to go back to the selected or can you equal it to itself? I feel like I just solved it, just by writing this out, but any comments or solutions would be helpful. (I tried to do an is statement, but it keeps on messing up and more cases arise.)
case 'Tab 2'
if app.NumberOfTabs.Value > 2
app.TabGroup.SeletedTab = event.OldValue;
end
case 'Tab 3'
if app.NumberOfTabs.Value > 3
app.TabGroup.SeletedTab = event.OldValue;
end
case 'Tab 4'
if app.NumberOfTabs.Value > 4
app.TabGroup.SeletedTab = event.OldValue;
end
I would appreciate the help, if you guys can!

采纳的回答

Sean
Sean 2023-9-20

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by