3

I'm producing around 1000 videos in a loop with Matlab.The videos contain a 1000x1000 pixel figure with changing plots inside, initiated by

h=figure('units','pixels','Position',[0 0 1000 1000])

Each Video contains about ~20-200 frames, with each figure consisting of 5 subplots and textbox (here is an example of one frame).

Everything works fine for around 800 videos (inside a loop) when suddenly the figure size of one figure is only 1000*999 pixels. When this error happens, I tried to resize the height, but that doest work. Neither by dragging the window,nor by using the code:

set(gcf, 'Units', 'pixels','Position',[0 0 1000 1000])

But I can resize the width. Anyone know what can causes this problem?

EDIT: When i use opengl software, everthing works fine, but the quality is by far not as good.

The basic loop (I tried to shorten as good as possible):

   for i=1:length(idx) %loop over video
            %Create figure and title
            fh=figure('units','pixels','Position',[0 0 1000 1000])

            subQ=subplot_tight(3,2,[1,2])
            p_Q=plot(Q_time_num(idx_Q(i,1):idx_Q(i,2)), Q(idx_Q(i,1):idx_Q(i,2)),...
                Q_time_num(idx_Q(i,1):idx_Q(i,2)), Q_trunc(idx_Q(i,1):idx_Q(i,2)),'--')

            an_tit=annotation('textbox',[0.48 0.89 0.1 0.1],'String',tit_string)
            set(an_tit, 'horizontalAlignment', 'center')

            for i_s = 1:numel(ind) %loop over each frame

                for ii=1:4length(fieldnames(Data)) %loop over the 4 subplots
                    if i_s==1
                        sub_p(ii)=subplot_tight(3,2,ii+2)
                        h1(ii)=plot(bord(:,2),bord(:,1),'color','k','linewidth',2,'Parent',sub_p(ii));
                        c(ii)=colorbar;

                        title([infos{ii,3},' - [',infos{ii,2},']'],'Interpreter','none')
                        hold on;
                        p(ii)=scatter(bord(cc,2),bord(cc,1),'MarkerEdgeColor',[0 0 0],...
                            'MarkerFaceColor',[0 0 0],'LineWidth',2,'Parent',sub_p(ii));
                        hold off;
                    end

                    hold on
                 [C,h2(ii)]=contourf(longitude,latitude,rot90(flipud(temp)),'Parent',sub_p(ii)) ;
                    clabel(C,h2(ii))
                    set(sub_p(ii),'Position',A(ii+1,:));
                    set(gcf, 'color', 'white');
                    uistack(h1(ii),'up',3)
                    uistack(p(ii),'up',3)
                end
                moving_img %save figure as frame
                delete(line_Q);delete(h2(:)); delete(text_an)
            end
            close all
        end
Squeezie
  • 361
  • 2
  • 14
  • Do you create the figure within the loop over and over again? If you try to create the video for which the error pops up outside of the loop on its own, does it work? – Ne_Plus_Ultra Jun 21 '17 at 13:02
  • Before each iteration of the loop i close all figures and create a new figure. Inside each videos loop i just replace the plots. I will try that. – Squeezie Jun 21 '17 at 13:17
  • Can you add the basic structure of the loop to the main question please? – Ne_Plus_Ultra Jun 21 '17 at 13:18
  • Maybe you need to add a small `pause(2)` or something like that in the end of each loop, so the java engine has time to process everything properly – Ander Biguri Jun 21 '17 at 13:20
  • @AnderBiguri, I created it outside of the loop before getting the frame. Same problem. – Squeezie Jun 21 '17 at 13:31
  • 2
    You definetly need a `drawnow` after all the plotting stuff, and I'd put a `pause(0.5)` or so just before opening a new figure – Ander Biguri Jun 21 '17 at 13:33
  • Well, we now know it is most likely not something in the loop itself. That's a start. Is there anything special/different about what you try to draw in the specific problematic iteration? Are videos which were supposed to be created after said problematic video created correctly? – Ne_Plus_Ultra Jun 21 '17 at 14:17
  • I'm guessing that after you fix your original question, you might want to improve performance. Take a look at [this question and answer](https://stackoverflow.com/q/28174583/3169029) for a method to not draw figure windows but do save them. I guess your `moving_img` function or script does save the active figure window as an image or as a frame in a video file. In that case, never actually drawing the rendered figure window can speed up things a lot, since you draw more than 20000 figures with quite complex contents. – Erik Aug 01 '17 at 08:18

0 Answers0