How to play my video while my graph animates?
    7 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
I am trying to update a graph animation in sync with a played movie. How do i structure the while loop so that when the movie(...) line is running the plot loop is running as well?
I have a movie playing using the movie function a la:
movie(video, mov,1,xyloObj.FrameRate)
I am following this code for a graph
%# control animation speed
DELAY = 0.01;
numPoints = 600;
%# create data
x = linspace(0,10,numPoints);
y = log(x);
%# plot graph
figure('DoubleBuffer','on')                  %# no flickering
plot(x,y, 'LineWidth',2), grid on
xlabel('x'), ylabel('y'), title('y = log(x)')
%# create moving point + coords text
hLine = line('XData',x(1), 'YData',y(1), 'Color','r', ...
    'Marker','o', 'MarkerSize',6, 'LineWidth',2);
hTxt = text(x(1), y(1), sprintf('(%.3f,%.3f)',x(1),y(1)), ...
    'Color',[0.2 0.2 0.2], 'FontSize',8, ...
    'HorizontalAlignment','left', 'VerticalAlignment','top');
%# infinite loop
i = 1;                                       %# index
while true      
    %# update point & text
    set(hLine, 'XData',x(i), 'YData',y(i))   
    set(hTxt, 'Position',[x(i) y(i)], ...
        'String',sprintf('(%.3f,%.3f)',[x(i) y(i)]))        
    drawnow                                  %# force refresh
    %#pause(DELAY)                           %# slow down animation
        i = rem(i+1,numPoints)+1;                %# circular increment
        if ~ishandle(hLine), break; end          %# in case you close the figure
    end
I can sync the movement of the red circle by settling delay to my frame rate but i cannot get both to run simultaneously.
0 Commenti
Risposte (1)
  Geoff Hayes
      
      
 il 16 Mag 2015
        matlabuser12 - rather than calling the movie function, you may want to display the frames yourself so that when a frame appears you update your other figure. Using the xylophone example, instead of
 movie(video, mov,1,xyloObj.FrameRate)
you could do
 nFrames = xyloObj.NumberOfFrames;
 for k=1:nFrames
       image(mov(k).cdata,'Parent', axesHandle);
       pause(1/xyloObj.FrameRate);
 end
where axesHandle is the handle to the parent axes to draw the frame on.
Try integrating the above into your while loop. You don't necessarily need to use the for loop but something similar will be needed to grab the kth frame at each iteration.
0 Commenti
Vedere anche
Categorie
				Scopri di più su Animation in Help Center e File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

