Problems animating a surf plot.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Argento
el 12 de Mzo. de 2016
Comentada: Argento
el 12 de Mzo. de 2016
Hello all, I am employing MATLAB to solve some basic PDEs (transport equation) using various numerical schemes. I have no problem creating a 2-d movie of the solution over time. However, when I try the same trick with surf, I either just get the plot of the final frame, or if I try to index it, I get the error:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/157622/image.png)
Error using surf (line 69) Z must be a matrix, not a scalar or vector.
How can I fix this? Below I've attached my code, I appreciate all the help.
W.U.
1 comentario
Image Analyst
el 12 de Mzo. de 2016
Editada: Image Analyst
el 12 de Mzo. de 2016
Note: REQUIRES SYMBOLIC TOOLBOX (so I can't run it). I've added that to the product list.
Respuesta aceptada
Ced
el 12 de Mzo. de 2016
Editada: Ced
el 12 de Mzo. de 2016
The code runs without error. I was not quite sure what you were trying to plot in 3D. I mean, you have one nx x nt matrix. If you index it, you have a vector... how should surf plot that?
My best guess is that you want to do something like this:
U_movie = zeros(size(U_t_x));
U_movie(:,1) = U_t_x(:,1);
h = surf(U_movie);
xlim([0 100])
ylim([0 201 ])
view(74, 34)
title(mytitle)
grid on
M(1) = getframe;
for i=2:Tsteps
U_movie(:,i) = U_t_x(:,i);
set(h,'ZData',U_movie);
M(i) = getframe;
pause(0.1)
end
There might be a more elegant way of doing this, but it works :).
I don't think the angle is so good, I would also only plot a subset of the points to make the edges less prominent, but I've kept these settings as you had them for now.
Note the usage of the "set" function. It's usually a good practice when updating the data in an otherwise constant plot (instead of recreating the figure over and over), and will speed up the plotting process significantly.
Hope this helps.
Más respuestas (0)
Ver también
Categorías
Más información sobre Geometry and Mesh en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!