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 (최근 30일)
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);

채택된 답변

Walter Roberson
Walter Roberson 2015년 9월 6일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Axes Appearance에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by