如何将轴命令与 semilogy 条形图一起使用
How to use the axis command with semilogy bar plots
我正在尝试使用 semilogy 条形图制作 matlab 电影,但我的轴会随着每个新值而不断变化,尽管我使用的是 axis-cmd。
代码示例:
我的输入信号 u 是不同频率区域的能量,每个时间步长有 100 个值。
fs = 22050
x_min = 0;
x_max = 22100;
y_min = 0;
y_max = 10^4;
for i = 1:length(u)
bar(fs/100:fs/100:fs,u(i,:));
set(gca,'YScale','log')
axis([x_min x_max y_min y_max])
drawnow
frame = getframe(gcf);
writeVideo(v,frame);
end
对于每个新帧,轴不断变化,我在谷歌搜索问题时没有找到任何答案。
非常感谢您的帮助。
这是我在 R2015b 中尝试的一个工作示例(请注意,我保存的是 GIF 动画而不是视频,以便在此处发布结果):
x = 1:10;
Y = exp(rand(30,numel(x))*8);
h = bar(x, Y(1,:));
set(gca, 'YScale','log', 'XLim',[0 11], 'YLim',[1 3000])
for i=1:size(Y,1)
set(h, 'YData',Y(i,:))
drawnow
% save animation to GIF file
[im,map] = rgb2ind(frame2im(getframe(gcf)), 256);
if i==1
imwrite(im, map, 'out.gif', 'gif', 'DelayTime',0.5, 'LoopCount',Inf);
else
imwrite(im, map, 'out.gif', 'gif', 'DelayTime',0.5, 'WriteMode','append');
end
end
我正在尝试使用 semilogy 条形图制作 matlab 电影,但我的轴会随着每个新值而不断变化,尽管我使用的是 axis-cmd。 代码示例: 我的输入信号 u 是不同频率区域的能量,每个时间步长有 100 个值。
fs = 22050
x_min = 0;
x_max = 22100;
y_min = 0;
y_max = 10^4;
for i = 1:length(u)
bar(fs/100:fs/100:fs,u(i,:));
set(gca,'YScale','log')
axis([x_min x_max y_min y_max])
drawnow
frame = getframe(gcf);
writeVideo(v,frame);
end
对于每个新帧,轴不断变化,我在谷歌搜索问题时没有找到任何答案。 非常感谢您的帮助。
这是我在 R2015b 中尝试的一个工作示例(请注意,我保存的是 GIF 动画而不是视频,以便在此处发布结果):
x = 1:10;
Y = exp(rand(30,numel(x))*8);
h = bar(x, Y(1,:));
set(gca, 'YScale','log', 'XLim',[0 11], 'YLim',[1 3000])
for i=1:size(Y,1)
set(h, 'YData',Y(i,:))
drawnow
% save animation to GIF file
[im,map] = rgb2ind(frame2im(getframe(gcf)), 256);
if i==1
imwrite(im, map, 'out.gif', 'gif', 'DelayTime',0.5, 'LoopCount',Inf);
else
imwrite(im, map, 'out.gif', 'gif', 'DelayTime',0.5, 'WriteMode','append');
end
end