App Designer: Subplots in uiplane

조회 수: 17 (최근 30일)
AdiKaba
AdiKaba 2020년 7월 27일
댓글: Adam Danz 2020년 7월 28일
I want to plot in uipanel in App Designer and crated subplots as shown below. I want to plot in the uipanel and I want the title of the panel to change to the type of analysis I am performing. For example, I have a function that performs Transform domain analysis and display the results in subplots and change the title of the panel. I also have another function subplots are displayed in the same uipanel but with different titles. All this works fine.However, the plots are displayed in a new App window. For example, I have a function called Plots (shown below) which is connected to the App using a callback function. When this function is called, it always plots results in a new App window. I want the results to show in an App from which the function is called.
How could I prevent App designer from opening a new window?
function [] = Plots(inputData)
myMainGUICopy = MainGUI;
ResultsPanel = myMainGUICopy.ResultsPanel;
%
ResultsPanel.Title = 'Transform Domain Representation of Input Data';
%Create Subplots
ax1 = subplot(2,3,1,'Parent',ResultsPanel);
ax2 = subplot(2,3,2,'Parent',ResultsPanel);
ax3 = subplot(2,3,3,'Parent',ResultsPanel);
ax4 = subplot(2,3,4,'Parent',ResultsPanel);
ax5 = subplot(2,3,5,'Parent',ResultsPanel);
ax6 = subplot(2,3,6,'Parent',ResultsPanel);
...
plot(ax1,...)
plot(ax2,...)
...
plot(ax6,...)
  댓글 수: 4
Adam Danz
Adam Danz 2020년 7월 28일
편집: Adam Danz 2020년 7월 28일
But where does MainGUI come from? Each function has its own workspace so the variable must either be defined within the function or it must be a global variable.
Pass the MainGUI variable to the Plots() function. If the Plots() function is embedded within the App Designer code, then the first input should be app (or whatever you named that variable, if you renamed it). If the Plots() function is external to App Designer, you should pass that variable in as an input. Do not use global variables.
Also, there is no need to copy the MainGUI variable. I don't understand why you would need to do that.
Are the number of subplots and the subplot layout always the same or does that vary?
AdiKaba
AdiKaba 2020년 7월 28일
You brought up valid points. I passed the app object to each function and removed the line that copies MainGUI; I inherited the code and wasn't why MainGUI was being copied. The number of subplots vary based on the type of analysis performed. Since all functions are external to App Designer, I have the flexibility to define subplots based on the number of plots.
Thank you.

댓글을 달려면 로그인하십시오.

채택된 답변

Adam Danz
Adam Danz 2020년 7월 28일
편집: Adam Danz 2020년 7월 28일
Since this isn't your code, I don't have to worry about sounding insulting when I say that this code is a mess! :)
I wouldn't use subplot() to create the axes in an app. Instead, look into tiledlayout which returns a tiled layout object used to define the number and arrangement of axes within the panel.
For example,
% Clear existing axes on panel and set new layout as 2x2
% The axis will not appear yet. app.Panel is the UI panel handle.
t = tiledlayout(app.Panel, 2, 2);
% Access first subplot-tile for plotting
ax = nexttile(t);
plot(ax, ___)
% Access next subplot-tile for plotting
ax2 = nexttile(t);
plot(ax2, ___)
  댓글 수: 2
AdiKaba
AdiKaba 2020년 7월 28일
Thank you, this is cleaner and efficient :)
Adam Danz
Adam Danz 2020년 7월 28일
Glad I could help.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by