Problems animating a surf plot.
1 回表示 (過去 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
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
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.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Geometry and Mesh についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!