Edit tile properties like legend or title out of tiledlayout nextline lines

28 vues (au cours des 30 derniers jours)
I have a tiledlayout that I passed out of a function . I want to edit the properties of the axes in the tiled layout. Usually, it is done within the nexttile lines, But I am trying to do it after I finish creating the tiled layout.
t = tiledlayout (2,3) ;
t.Children has the axes array stored.
I tried editing the legend as following
And this does apply the legend to first axis from top left , i.e in t, the axis at (1,1) gets the legend .
However, if I add another line to change it or edit the legend text 'test' as following
This now , somehow, does not apply to the same axis on which it did earlier. It would apply to a different axis , (1,2) to be exact. So every time I execute this line, it applies to the next tile in the layout.
Does this mean that the axes array changes everytime the line legend is executed?
How can I have lines with which I can change the legend or orther properties to the axes?

Réponse acceptée

Adam Danz
Adam Danz le 23 Mar 2023
Modifié(e) : Adam Danz le 23 Mar 2023
I understand that you want to access a vector of TiledLayout axes and to keep put them in order.
If you're using MATLAB R2022b or later, you can use tilenum to get the tile index number for each tile. Then you can sort the vector of handles.
Create tiledlayout and plots
tcl = tiledlayout(3,2);
for i = 1:6
Get axis handles and sort them in order
axh = findobj(tcl,'Type','axes');
axidx = tilenum(axh);
axh = axh(axidx);
Add legends using the problem shown in the question.
title(axh(1)', '1')
title(axh(2)', '2')

Plus de réponses (0)




Community Treasure Hunt

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

Start Hunting!

Translated by