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

25 Ansichten (letzte 30 Tage)
Sean
Sean am 13 Sep. 2023
Beantwortet: Sean am 20 Sep. 2023
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!

Akzeptierte Antwort

Sean
Sean am 20 Sep. 2023

Weitere Antworten (0)

Kategorien

Mehr zu App Building finden Sie in Help Center und File Exchange

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by