How to create a nested tile layout with TileAx?

4 次查看(过去 30 天)
Hi,
I am trying to create figures for different conditions using a tile layout. Within each of these figures I have 5 subfigures but I cannot seem to get this to work. I want each of the condition figures to be in a differnet quadrant.
%T = tiledlayout(2, );
% TAx_all = zeros(1,length(conditions.condition));
titles = {'2Hz left', '2Hz right', '7.5Hz left', '7.5Hz right'};
for j=1:length(conditions.condition)
condition = conditions.condition(j);
filename = string(task) + '_P' + participant_number + '_' + string(condition{1}) + '.prepro';
% Load prepro file
prepro = load(filename, '-mat');
prepro.dcAvg = squeeze(prepro.dcAvg);
dists1 = DOTHUB_getSDdists(prepro.SD2D);
% variables for plotting
blockendtime = 10;
xminLim = -5;
xmaxLim = 15;
rngs = [[0 10]; [10 20]; [20 27.5]; [27.5 32.5]; [32.5 37.5]]; %[37.5 42.5]; %[42.5 Inf]]; %boundary values excluded
rngElem = length(rngs);
% populate the error bar filters, but only include good channels
filts = cell(1, rngElem);
for i = 1:rngElem
rowFilts = find(prepro.SD2D.MeasListAct(1:end/2)==1 & dists1' > rngs(i,1) & dists1' < rngs(i,2));
filts{i} = rowFilts;
end
% create panelled plot layout
figure;
tile = tiledlayout(1,rngElem);
tileAx = zeros(1,rngElem);
for i = 1:rngElem
% Get averaged data and error data from each SD range
Avg_Channel = squeeze(mean(prepro.dcAvg(:,:,filts{i}),3));
Std_Channel = squeeze(std(prepro.dcAvg(:,:,filts{i}),0,3));
Std_Error = Std_Channel/sqrt(length(participant_list));
% Plot each SD range with error bars
tileAx(i) = nexttile;
plot(tHRF, Avg_Channel(:,1), 'r', "LineWidth", 1); hold on
plot(tHRF, Avg_Channel(:,2), 'b', "LineWidth", 1); hold on
plot(tHRF, Avg_Channel(:,3), 'g', "LineWidth", 1); hold on
xlim(tileAx(i),[xminLim xmaxLim]);
shadedErrorBar(tHRF, Avg_Channel(:,3),Std_Error(:,3),{'g','LineWidth',1.5},0.6);
shadedErrorBar(tHRF, Avg_Channel(:,2),Std_Error(:,2),{'b','LineWidth',1.5},0.6);
shadedErrorBar(tHRF, Avg_Channel(:,1),Std_Error(:,1),{'r','LineWidth',1.5},0.6);
title_small = strcat(string(rngs(i,1)), "-", string(rngs(i,2)), " mm");
title(title_small);
yl = ylim;
pt = patch([0 0 blockendtime blockendtime],[yl(1)-3 yl(2)+3 yl(2)+3 yl(1)-3],[0.9 0.9 0.9]);
pt.EdgeColor = 'None';
pt.FaceAlpha = 0.5;
set(gca,'children',flipud(get(gca,'children')))
hold off
ylim(yl);
hold off
end
tile.XLabel.String = "Time (s)";
tile.XLabel.FontSize = 22;
hold on
tile.YLabel.String = "Concentration Change (\muM)";
tile.YLabel.FontSize = 22;
hold on
legend("","HbO", "","","","HbR", "","","","HbT");
hold on
tile.Title.String = titles{j};
linkaxes(tileAx,'y');
end
I would massively appreciate any help, thanks!
  1 个评论
Joe Vinciguerra
Joe Vinciguerra 2023-4-6
编辑:Joe Vinciguerra 2023-4-6
Your code seems to work fine for me (using random data since yours has not been provided). What's it doing that is different from your expectation?

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息

标签

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by