matlab - 将单个 MATLAB 图组合成一个图形:修改脚本是最佳选择吗?
问题描述
下面的脚本生成七个单独的图形(每个图形包括两个图)。我想将它们组合成一个包含所有 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
解决方案
在你已经绘制它们之后,你不能轻易地将它们“合并”成一个图形。你可以做的是放置命令
hold on
在函数之后figure
和
hold off
最后之后title
。这将确保所有绘图都绘制在当前活动图形上。
有关该函数的更多详细信息,请参阅 MATLAB 文档hold
:
https ://www.mathworks.com/help/matlab/ref/hold.html
推荐阅读
- python-3.x - QTreeWidget 和 QPainter 组合
- macos - 如何在 MacOS 上安装 lua 开发库?
- python - Python中的采访数据:计算由说话者分隔的某个共现
- batch-file - 为什么由于一些奇怪的字符编码问题而无法处理来自文本文件的 wmic 数据?
- ruby-on-rails-5 - Rails 5 Active Storage 回形针式缩略图表单预览
- mongodb - $group 之后未显示 $project $lookup 值
- php - 将变量“图表”从控制器传递到视图
- c++ - 注入时未调用 DllMain(),但使用 LoadLibrary() 调用
- python - 在没有系统 python 的情况下从 pip venv 运行 python 程序
- c# - Docker 绑定挂载到环境变量(在 ASP.NET Core 中)