Problems animating a surf plot.

2 次查看(过去 30 天)
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:
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 个评论
Image Analyst
Image Analyst 2016-3-12
编辑:Image Analyst 2016-3-12
Note: REQUIRES SYMBOLIC TOOLBOX (so I can't run it). I've added that to the product list.

请先登录,再进行评论。

采纳的回答

Ced
Ced 2016-3-12
编辑:Ced 2016-3-12
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.
  1 个评论
Argento
Argento 2016-3-12
Thanks Ced, that does it. I was trying to do exactly what you did but could not figure out who to get surf to plot at every time step. Thanks a lot for the help!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Geometry and Mesh 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by