Animation of PATCH-Figure
Afficher commentaires plus anciens
Hi,
I tried to create an animation with PATCH but unfortunately, it only shows the final result and does not animate the whole process.
Just the values of the colorbar change.
(Picture at the bottom).
Do you have any idea that how can I create a color-changing process?
My code can be read below:
STEPS = 40;
q = zeros(14,STEPS);
q(:,1) = [0;0;0;0;0;0;0;0;0;0;0;0;0;0];
q(:,2) = [0;0;0.01;0.001;0.01;0.001;0;0;0.0025;0.00025;0.0025;0.00025;0.005;0];
for i = 3 : STEPS
q(:,i) = q(:,i-1) * 1.05;
end%for
RGB = [0 0 1
0 0.5 1
0 1 1
0 1 0.5
0 1 0
0.5 1 0
1 1 0
1 0.5 0
1 0 0];
Q = q(:,STEPS);
Q = Q(1:2:end);
% data for patch
msh_1.nn_3sz = [3,2,7;2,6,7;5,3,7;6,5,7];
msh_1.nn_4sz = [5,4,1,6];
msh_1.xy = [0,0;2,0;2,1;0,1;1,1;1,0;1.5,0.5];
figure (8)
qxy="qx";
for i = 1:STEPS
Q = q(:,i);
QX = Q(1:2:size(Q,1)-1);
QY = Q(2:2:size(Q,1));
switch qxy % displacements in X and Y dimensions
case "qx"
QQ = QX;
case "qy"
QQ = QY;
case "q"
QQ = sqrt(QX.^2+QY.^2);
end%switch
set(gcf, 'color', 'w')
colormap(RGB);
colorbar('EastOutside')
patch('Faces',msh_1.nn_3sz,'Vertices', msh_1.xy,'FaceVertexCData',QQ,'FaceColor','interp')
patch('Faces',msh_1.nn_4sz,'Vertices', msh_1.xy,'FaceVertexCData',QQ,'FaceColor','interp')
axis equal
drawnow()
end%for
The PATCH figure:

Do you have any idea how can I solve it?
Thank you so much for your helpful comments!
Réponse acceptée
Plus de réponses (1)
Sorry did not see the much better answer above before i answerd
Right now you only view the second call of patch (msh_1.nn_4sz) in each loop as it overwrites msh_1.nn_3sz. To view both in the same figure use hold on and hold off. Then you get an animation where new colours is added. Is that what you wanted to animate?
Other tips:
If you write in live script and run the code you can save your animation as a GIF in the figure options (hover over the figure)
set(gcf, 'color', 'w')
colormap(RGB);
colorbar('EastOutside')
patch('Faces',msh_1.nn_3sz,'Vertices', msh_1.xy,'FaceVertexCData',QQ,'FaceColor','interp')
hold on % hold the first patch
patch('Faces',msh_1.nn_4sz,'Vertices', msh_1.xy,'FaceVertexCData',QQ,'FaceColor','interp')
axis equal
drawnow
hold off % turn off before the next iteration
1 commentaire
Kovacs Mario
le 1 Mar 2024
Catégories
En savoir plus sur Animation dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!