سؤال

So, as I browse through google on the problem of how to create a .gif animation from series of .fig files, i stumble through one that uses .sdf file, I tried to rewrite the program to work for my .fig files

clear all;
close all;

dynam = 156;
gif_fps = 24; 
video_filename = 'A.gif';
fh = figure(1);

for i = 1:dynam
    F_data = getdata(['F' num2str(i,'_%03i', '.fig');
    imagesc(F_data);
    drawnow;
    frame = getframe(fh);
    im = frame2im(frame);
    [imind,cm] = rgb2ind(im,256);
    if a == 0;
        imwrite(imind,cm,video_filename,'gif', 'Loopcount',inf);
    else
        imwrite(imind,cm,video_filename,'gif','WriteMode','append','DelayTime',1/gif_fps);
    end
end

so it pops up an error saying

???     frame = getframe(fh);
                   |
Error: The expression to the left of the equals sign is not a valid target for an assignment.

which I don't understand why this is happening, and I also notice that Matlab is not drawing the figs, the figure that pop us is completely blank.

هل كانت مفيدة؟

المحلول

The error comes from a typo. The line

F_data = getdata(['F' num2str(i,'_%03i', '.fig'); %bracket missing at the end

should read

F_data = getdata(['F' num2str(i,'_%03i', '.fig']);

Without the bracket, Matlab sees

['F' num2str(i,'_%03i', '.fig');
imagesc(F_data);
drawnow;
frame 

as a single string of letters. The code's logic is therefore a = b = c and matlab can't interpret this.

To prevent such errors, matlab and its editor have some nice coloring schemes that highlight in dark red the text following an opening string ', and turn the full string in purple when a closing ' is used. If you see some red characters spanning over several lines, that's a sign of a potential problem. Unfortunately, brackets don't have such behavior...


Additionnaly, what about opening the figures per se? You will see if each figure renders well (no blank) and will be able to capture the frame.

for i = 1:dynam

    %open, get the frame from and close the figure 
    fh_tmp = open(['F' num2str(i,'_%03i', '.fig']) 
    frame = getframe(fh_tmp);
    close(fh_tmp);

    im = frame2im(frame);
    ...

I still struggle to find where the getdata is coming from.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top