Generate animation from graph

Asked

Viewed 2,979 times

1

I am generating a graph with the following command:

X = linspace(0, 1, n);
Y = linspace(0, 1, n);
surf(X,Y,B(:,:));

But how to make it generate an animation of the graphic? I know nothing of MATLAB...

1 answer

2

It is relatively simple to generate animations in Matlab, you need to create a for and with each step generate the desired output, call the function getframe immediately after the function responsible for generating the graph, this function acts as a print screen in the chart window, place each frame in a position and finally call the function movie to execute the captured frames, the information you have passed so far is not sufficient to understand what is the expected output of your algorithm, or you expect movement to occur in your linearly created vectors(X,Y) or that they remain fixed and that only animation occurs in B, you need to define this, a pseudo example of the steps explained above:

for j = 1:50
     %A cada passo um surf diferente deve ser gerado de acordo com a sua necessidade 
     surf(X,Y,B(:,:));
     %captura os frames
     anima(j) = getframe;
end
%executa a animação no matlab
movie(anima,50)

Run this example to familiarize yourself and see the result:

Z = peaks;
figure('Renderer','zbuffer');
for j = 1:20
    surf(sin(2*pi*j/20)*Z,Z)
    F(j) = getframe;
end
movie(F,20)
  • Thank you for the answer, well my code is generating this wave: Imgur I wanted the animation that could see the progress of this wave, but I could not with his example.

  • It’s like I told you without having the full code there’s no way to help you because no one knows if your wave is advancing in X Y or B

  • Looking quickly you can notice that X and Y are static you need to change B in each processed frame

Browser other questions tagged

You are not signed in. Login or sign up in order to post.