0
votes

I´m trying to make a matlab movie using a semilogy bar plot but my axis keep changing for every new value eventhough I´m using the axis-cmd. Code-example: My input signal u is the energy in different frequency areas, and has 100 values for every time step.

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

For every new frame the axis keeps changing and I haven´t found any answer when googling the issue. Help is much appreciated.

1
Please, poste the whole code. What is u(i,:)? How are x_min x_max y_min y_max defined? - il_raffa

1 Answers

2
votes

Here is a working example I tried in R2015b (note I'm saving a GIF animation instead of a video for the purpose of posting the result here):

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

animation