a tiledlayout issue via a subfunction
1 view (last 30 days)
Show older comments
When I run the main code (all the below are sample codes), the tiledlayout figure appears but figures were been drawned seperately. When I remove all the sets and other stuff from the PlotSubFunction, the codes works properly. Could you help me to solve the issue please? I have to keep the sets and the other stuff. So, the solution might be somehow a different approach to keep them. I don't know really.
The main code :
m=3;
n=2;
PlotTiled(m,n)
The PlotTiled function :
function PlotTiled(m,n)
tempTiledFig = tiledlayout(m,n,'TileSpacing','compact','Padding','compact');
for tempPlotTileRow = 1:m
for tempPlotTileCol = 1:n
randCol = m+n+1;
nexttile(tempTiledFig)
PlotSubFunction(randCol);
end
end
end
The PlotSubFunction function:
function PlotSubFunction(randCol)
randNums = rand(1,randCol);
figSubPlots = figure('Name','A11', 'NumberTitle','off',...
'PaperOrientation','landscape','PaperType','A2',...
'WindowState','maximized','Renderer','painters');
axes1 = axes('Parent',figSubPlots,'Position',[0.13 0.11 0.775 0.815]);
hold(axes1,'on');
plot(randNums);
box(axes1,'on');
hold(axes1,'off');
set(axes1,'TickDir','out','XGrid','on','YGrid','on');
xlim([0 length(randNums)]);
end
0 Comments
Accepted Answer
Matt J
on 12 Apr 2022
Edited: Matt J
on 12 Apr 2022
PlotTiled(3,2)
function PlotTiled(m,n)
tempTiledFig = tiledlayout(m,n,'TileSpacing','compact','Padding','compact');
figSubPlots = figure('Name','A11', 'NumberTitle','off',...
'PaperOrientation','landscape','PaperType','A2',...
'WindowState','maximized','Renderer','painters');
for tempPlotTileRow = 1:m
for tempPlotTileCol = 1:n
randCol = m+n+1;
ax=nexttile(tempTiledFig);
PlotSubFunction(randCol,ax);
end
end
end
function PlotSubFunction(randCol,axes1)
randNums = rand(1,randCol);
% hold(axes1,'on');
plot(randNums);
box(axes1,'on');
% hold(axes1,'off');
set(axes1,'TickDir','out','XGrid','on','YGrid','on');
xlim([0 length(randNums)]);
end
More Answers (1)
See Also
Categories
Find more on Annotations 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!