Joshua Jenkins
Joshua Jenkins

Reputation: 267

How to Programmatically Change Tabs in MATLAB GUI

I'm currently trying to program a line in my MATLAB source that will change the tabs of my GUI that I've created using uicontrol, uitabgroup, uitab, etc.

What I want is a single line piece of code that will change the currently selected tab of a GUI as shown in this documentation: https://www.mathworks.com/matlabcentral/answers/166175-how-to-programmatically-select-a-tab-in-a-uitabgroup

However, despite no errors showing, it doesn't change the tab. I'm currently using MATLAB 2011b and find this concerning since the post was made in almost 2015.

Could anyone direct me in an appropriate direction or know of any resources regarding this issue for older versions of MATLAB?

Upvotes: 3

Views: 2239

Answers (2)

ePi272314
ePi272314

Reputation: 13437

In modern versions of Matlab

Set the property SelectedTab of a TabGroup object to the handle of the desired tab.

function GoToSomeTabButtonPushed(app, event)

    app.TabGroup.SelectedTab = app.SomeTab;

    % Alternatively, assuming the desired tab is the second:
    app.TabGroup.SelectedTab = app.TabGroup.Children(2);

end

See a live example here.

Upvotes: 0

Suever
Suever

Reputation: 65430

uitab and uitabgroup weren't "officially" documented functions until R2014b so it's no surprise that they may have changed between their introduction in 2004, your version from 2011, and the "official" documentation from 2014.

Accorinding to Yair's blog, there were a number of changes to uitab and uitabgroup over the years, particularly in how to programmatically select a tab. It appears that for your version, setting the SelectedIndex (a hidden property) should programmatically select the tab.

htabgroup = uitabgroup();
htab1 = uitab(htabgroup, 'Title', 'Tab1');
htab2 = uitab(htabgroup, 'Title', 'Tab2');

set(htabgroup, 'SelectedIndex', 2)

Upvotes: 1

Related Questions