Problems animating a surf plot.
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
Image Analyst
am 12 Mär. 2016
Bearbeitet: Image Analyst
am 12 Mär. 2016
Note: REQUIRES SYMBOLIC TOOLBOX (so I can't run it). I've added that to the product list.
Akzeptierte Antwort
Ced
am 12 Mär. 2016
Bearbeitet: Ced
am 12 Mär. 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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Geometry and Mesh finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!