2

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.

Amro
  • 123,847
  • 25
  • 243
  • 454
user2683631
  • 101
  • 1
  • 11
  • I don't get the `frame = getframe(fh);` in your code and `frame_fmri` error. Is your copy/paste correct? – marsei Aug 22 '13 at 23:06
  • no, that is not a copy/paste error, when I copy/paste I usually rewrite all the variable to something I am used to, and when I created this help, I changed the variable to the mostly the original variable, the error that display there in fact that both variable are the same, because I also tried the same again when using the original variable – user2683631 Aug 22 '13 at 23:16
  • 1
    what is the `getdata` function? See [this](http://stackoverflow.com/a/11054155/97160) for an example of how to create an animated gif file. @Werner: I think you posted the wrong link – Amro Aug 23 '13 at 01:14
  • @Amro thanks, I was talking about [this one](http://stackoverflow.com/q/17197328/1162884) (even though I am not sure that it will be more useful than the previous one…) – Werner Aug 23 '13 at 01:29
  • @Werner Thanks with the example, I actually find many examples like this, but the troubling part with what I am having a bit different is that these use equations while I import .fig files that were generated by matlab to make the .gif file. The getdata, from I read about it in the desciption, is a way to import files. The example I used from is [this](http://stackoverflow.com/questions/17217774/making-a-gif-from-images). – user2683631 Aug 23 '13 at 03:38
  • @user2683631 I see, well, I dont know as much as Amro, but reading fast the codes and what you are doing, it seems that you need a valid figure axes handle to put your frame. What seems to be happening is that your figure doesnt have an axes already drawn, you need to draw something on the axes before you do `getframe`. Are you sure that your figure is being plot well? Maybe this `F_data = getdata(['F' num2str(i,'_%03i', '.fig');` and `imagesc(F_data);` are not working as expected. – Werner Aug 23 '13 at 03:49
  • @Werner Yes, as I mentioned above, I could not get the figure to display on the figure. I don't understand why the image is not being display on the figure. – user2683631 Aug 23 '13 at 12:32

1 Answers1

2

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.

marsei
  • 7,691
  • 3
  • 32
  • 41
  • Thank you for your help, the getdata is coming from the original thread that was creating .gif file. I did not notice one of the bracket is missing. – user2683631 Aug 23 '13 at 13:46
  • 1
    +1 nice catch. I would have used `hgload` instead of the generic `open` – Amro Aug 23 '13 at 14:04
  • Now I am running into problem with `??? Error using ==> imwrite Parameter names must be strings`. – user2683631 Aug 23 '13 at 14:06