How do I create a function (located in a separate file) that puts an interactive axes in a GUI tab (with the GUI defined in a script)?

1 view (last 30 days)
I created a ML GUI script similar to the following:
fig1 = figure; % Window for GUI
tbgp = uitabgroup(fig1); % Create a tab group for that window
t1 = uitab(tbgp, 'Title', 'tab1'); % Create first tab under 'tbgp'
t2 = uitab(tbgp, 'Title', 'tab2'); %Create 2nd tab under 'tbgp'
Now, I want to add 2 "interactive" axes/plots, each with different properties, in both of the tabs defined above. I can write code in the script, but I'd like to do this using a function defined in a separate file located on the same ML path(so that I can just call the function whenever I want a similar interactive plot on something. In this case, I want the plots on two different tabs).
<IN A SEPARATE FILE>
function showInteractivePlot( desiredTab )
axes(desiredTab); % Draw axes on the desired tab
pan(fig1); % I want to enable panning on the axes located on the 'desiredTab', which
% is itself located in fig1
end
In the end, I would like to do the following in my GUI script:
fig1 = figure; % Window for GUI
tbgp = uitabgroup(fig1); % Create a tab group for that window
t1 = uitab(tbgp, 'Title', 'tab1'); % Create first tab under 'tbgp'
t2 = uitab(tbgp, 'Title', 'tab2'); %Create 2nd tab under 'tbgp'
% Add interactive plot to t1
showInteractivePlot(t1);
% Add interactive plot to t2
showInteractivePlot(t2);

Accepted Answer

Walter Roberson
Walter Roberson on 6 Sep 2015
A uitab is not an axes, but an axes may be contained within a uitab.
Assuming that you want to create the axes within the tab, then
function showInteractivePlot( desiredTab )
ax = axes('Parent', desiredTab); % Create axes on the desired tab
h = pan(ancestor(desiredTab,'figure')); %panning needs to be turned on for the figure
setAllowAxesPan(h, ax, true); %enable panning for this axes
end

More Answers (0)

Categories

Find more on Axes Appearance in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!