a tiledlayout issue via a subfunction

1 view (last 30 days)
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

Accepted Answer

Matt J
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
  1 Comment
Emirhan Solmaz
Emirhan Solmaz on 13 Apr 2022
thank you. I would never think to use axes1 as an input.

Sign in to comment.

More Answers (1)

Emirhan Solmaz
Emirhan Solmaz on 12 Apr 2022
for now, I just remove the "figSubPlots" and "axis1" lines. I couldn't find a solution.

Community Treasure Hunt

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

Start Hunting!