Issue with tiledlayout and axes properties
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am using the tiledlayout function, and for each tile I am loading a figure (.fig) that I created in seperate Matlab scripts. When I run the script for the first time the script seems to work correctly in that it display all of the tiles. However, when I rerun the script, the tiles are shifted and not all figures are shown in the tiledlayout figure. For example, the figure in tile 1 shows in tile 2. I have attached the code I am using. After restarting Matlab, it works fine for the first run. After that, the same issue occurs.
Could you please advise me what I could to resolve this issue?
clear all; close all; clc;
%% Load figures + define axes
clear ax1t1 ax1t2 ax1t3 ax1t4 ax1t5 ax1t6 ax1t7 ax1t8
openfig('figures/t3_w1.fig','new');
% reset(ax1t1)
ax1t1=gca;
% set(ax1t1,'visible','on')
% reset(ax1t2)
openfig('figures/t3_w2.fig','new');
ax1t2=gca;
% set(ax1t2,'visible','on')
% reset(ax1t3)
openfig('figures/t4_w1.fig','new');
ax1t3=gca;
% set(ax1t3,'visible','on')
% reset(ax1t4)
openfig('figures/t4_w2.fig','new');
ax1t4=gca;
% set(ax1t4,'visible','on')
% reset(ax1t5)
openfig('figures/t6_w1.fig','new');
ax1t5=gca;
% set(ax1t5,'visible','on')
% reset(ax1t6)
openfig('figures/t6_w2.fig','new');
ax1t6=gca;
% set(ax1t6,'visible','on')
% reset(ax1t7)
openfig('figures/t7_w1.fig','new');
ax1t7=gca;
% set(ax1t7,'visible','on')
% reset(ax1t8)
openfig('figures/t7_w2.fig','new');
ax1t8=gca;
% set(ax1t8,'visible','on')
%%
clear tc2
figure;
tc2=tiledlayout(3,3,'TileSpacing','compact');
ax1t1.Parent=tc2;
ax1t1.Layout.Tile=1;
ax1t2.Parent=tc2;
ax1t2.Layout.Tile=2;
ax1t3.Parent=tc2;
ax1t3.Layout.Tile=3;
ax1t4.Parent=tc2;
ax1t4.Layout.Tile=4;
ax1t5.Parent=tc2;
ax1t5.Layout.Tile=5;
ax1t6.Parent=tc2;
ax1t6.Layout.Tile=6;
ax1t7.Parent=tc2;
ax1t7.Layout.Tile=7;
ax1t8.Parent=tc2;
ax1t8.Layout.Tile=8;
0 commentaires
Réponses (1)
Matt J
le 7 Fév 2022
Modifié(e) : Matt J
le 7 Fév 2022
I would do something like this. It gives me no trouble with repeat runs.
Names={'F1.fig','F2.fig'};
figure;
tc=tiledlayout(3,3,'TileSpacing','compact');
N=min(numel(Names), prod(tc.GridSize));
ax=gobjects(N,1); %preallocate
for i=1:N
ax(i) = loadTile(tc,Names{i},i);
end
function ax=loadTile(tc, name, ID)
p=openfig(name,'new','invisible');
ax=findobj(p,'Type','axes');
ax.Parent=tc;
ax.Layout.Tile=ID;
close(p)
end
0 commentaires
Voir également
Catégories
En savoir plus sur Plot Customization dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
