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
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 Center 및 File Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!