Creating subplots in a for cycle with App Designer

조회 수: 8 (최근 30일)
Iacopo
Iacopo 2022년 4월 26일
댓글: Kevin Holly 2022년 5월 2일
Hi all,
I’m trying to create subplots within a Panel with a for cycle in App Designer.
I was able to implement my first 3 subplots in a single panel in the following way:
app.subplot1(3,1,1,'Parent',app.Plotpanel);
plot(app.subplot1,t,a(:,1),’g’]);
hold(app.subplot1);
app.subplot2(3,1,2,'Parent',app.Plotpanel);
plot(app.subplot2,t,a(:,2),’b’]);
hold(app.subplot2);
app.subplot3(3,1,3,'Parent',app.Plotpanel);
plot(app.subplot3,t,a(:,3),’r’]);
hold(app.subplot3);
I have defined my subplots at the beginning of the app in the following way:
properties (Access = public)
subplot1 matlab.ui.control.UIAxes % Description
subplot2 matlab.ui.control.UIAxes % Description
subplot3 matlab.ui.control.UIAxes % Description
Supposing that my matrix a to plot is actually is bigger than 3 columns and I want to plot, at any cycle, columns 1,2,3 and then 4,5,6 and then 7,8,9 etc etc..
How can I implement that in App Designer? If I write this:
figure(n3) %n3 is the index that moves the columns of a in a for cycle
app.subplot1(3,1,1,'Parent',app.Plotpanel);
plot(app.subplot1,t,a(:,1),’g’]);
hold(app.subplot1);
I get this message: Unable to use a value of type matlab.ui.container.Panel as an index.
I would like that every set of 3 columns of the data are plotted as subplots in the same panel, maybe adding a sort of scrolling tab, is this possibile?
I hold Matlab R2022a. Thanks to everyone who will be able to help me.

채택된 답변

Kevin Holly
Kevin Holly 2022년 4월 26일
I created an app that generates tabs and subplots based on the dimensions of matrix a. Please see the app attached. I did not use subplots but used axes() instead.
  댓글 수: 3
Iacopo
Iacopo 2022년 5월 2일
Hi Kevin,
Do you also know how I can refresh the tabs content after changing the number of rows/columns? Because for example if I plot less number of columns after the first plot, the previous plots will still be displayed. Thank you
Kevin Holly
Kevin Holly 2022년 5월 2일
You can add the lines:
delete(app.TabGroup.Children(2:end))
delete(app.TabGroup.Children(1).Children)
within the push button callback as shown below
function PlotMatrixButtonPushed(app, event)
a = rand(app.RowsEditField.Value,app.ColumnsEditField.Value);
delete(app.TabGroup.Children(2:end))
delete(app.TabGroup.Children(1).Children)
for i = 4:3:size(a,2)
if ceil(i/3) > size(app.Panel.Children.Children)
uitab(app.TabGroup,'Title',['Set' num2str(ceil(i/3))])
end
end
for i = 1:3:size(a,2)
ax1 = axes(app.Panel.Children.Children(ceil(i/3)),"Position",[0.1300 0.7093 0.7750 0.2157]);
plot(ax1,a(:,i))
if i+1 <=size(a,2)
ax2 = axes(app.Panel.Children.Children(ceil(i/3)),"Position",[0.1300 0.4096 0.7750 0.2157]);
plot(ax2,a(:,i+1))
end
if i+2 <=size(a,2)
ax3 =axes(app.Panel.Children.Children(ceil(i/3)),"Position",[0.1300 0.1100 0.7750 0.2157]);
plot(ax3,a(:,i+2))
end
end
end

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by