我正在使用我编写的一个函数来加载和分析时间序列数据,如果系列包含一些有趣的东西,则绘制带有子图的图形。
这是代码的绘图部分:
if ~isempty(failure_x)
figure(call_n)
sgt = sgtitle(filename);
sgt.FontSize = 10;
subplot(5,1,1)
scatter([1: length(max_vol)], max_vol, '.')
set(subplot(5,1,1), 'XLim', [1, length(max_vol)])
subplot(5,1,2)
scatter([1:length(flow)], flow, '.')
set(subplot(5,1,2), 'XLim', [1, length(max_vol)])
subplot(5,1,3)
scatter([1: length(hlfv)], hlfv, '.')
set(subplot(5,1,3), 'XLim', [1, length(max_vol)])
subplot(5,1,4)
scatter([1: length(stats)], stats(:,2), '.')
set(subplot(5,1,4), 'XLim', [1, length(max_vol)])
subplot(5,1,5)
scatter(failure_x, failure_y)
set(subplot(5,1,5), 'XLim', [1, length(max_vol)])
end
当我从命令行单独调用此函数时,所有内容都正确绘制,但是当我从for循环中调用它时,最后一个子图总是似乎是来自for循环的下一个函数调用中图中的第一个子图。基本上,在迭代1处,子图(5,1,5)显示来自迭代2子波(5,1,1)的数据。
我添加了一个参数“call_n”来强制数字增加从for循环传入的数字,但这似乎没有解决问题。
有任何想法吗?我通常在python中编码所以我确定我做的事情很傻。
编辑:这是调用函数“detect_hlfv”的循环
for i = 1:length(fnames)
fname = strcat(data_dir, fnames(i).name);
failures = detect_hlfv(fname, i);
if length(failures) > 0
disp("FAILURE!")
disp(fname);
end
end
我是一个白痴!我忘了注释掉一个在实例化后绘制变量的代码调试行。问题解决了,谢谢你的帮助!