【发布时间】:2020-02-04 02:33:45
【问题描述】:
下面的脚本生成七个单独的图形(每个图形包括两个图)。我想将它们组合成一个包含所有 14 个地块的大图。我认为可能有两种解决方案:修改当前脚本或在绘制后将它们添加到一个中。我是个初学者;任何简单的解决方案将不胜感激。 (我的数据:https://www.dropbox.com/s/ggdh03lo10w85vv/Block-1.mat?dl=0)。
%% loop through frequencies, plot both channels next to each other
% desired # of points
nPoints = 200;
%vary this value to determine how closely you want the plots to be stacked on one another
stackvar = 0.00003;
% loop through frequencies
for f = 1:nf
% get channel 1 and 2 data for all attenuations (levels)
% and desired frequency converted
% from cell to matrix. time in rows, levels in columns
datatoplot_ch1 = cell2mat(Ch1D.mean(:, f)');
datatoplot_ch2 = cell2mat(Ch2D.mean(:, f)');
% plot in new figure for each frequency
figure
% loop through levels for this frequency
for ii = 1:nl
% plot fresh trace in first plot
if ii == 1
% ch 1
subplot(1, 2, 1)
plot(datatoplot_ch1(1:nPoints, ii) + stackvar*(nl - (ii - 1)), 'b');
% ch 2
subplot(1, 2, 2)
plot(datatoplot_ch2(1:nPoints, ii) + stackvar*(nl - (ii - 1)), 'r');
else
% channel 1
subplot(1, 2, 1)
hold on
plot(datatoplot_ch1(1:nPoints, ii) + stackvar*(nl - (ii - 1)), 'b');
hold off
% channel 2
subplot(1, 2, 2)
hold on
plot(datatoplot_ch2(1:nPoints, ii) + stackvar*(nl - (ii - 1)), 'r');
hold off
end
% add level label to identify trace
subplot(1, 2, 1)
text(1, stackvar*(nl - (ii - 1)), sprintf('%d', attens(ii)));
subplot(1, 2, 2)
text(1, stackvar*(nl - (ii - 1)), sprintf('%d', attens(ii)));
end
subplot(1, 2, 1)
title(sprintf('%s Ch1 %d', BLOCK, freqs(f)));
subplot(1, 2, 2)
title(sprintf('%s Ch2 %d', BLOCK, freqs(f)));
end
【问题讨论】:
-
组合成一个图是什么意思?您想将每个图添加到相同的两个轴上,还是想要一个包含所有图的 7x2 轴网格?
-
我想要一个包含 14 个图的最终大图(所以是的,7x2 轴)。谢谢你的慰问;我现在可以看到我的问题应该写得更清楚了。
-
是的,需要修改代码。
subplot(n, 2, 7)将绘制到 2x7 绘图数组中的nth 绘图。我希望在你的循环中计算n非常简单。
标签: matlab for-loop plot matlab-figure subplot