How to update a 3D surface plot?

조회 수: 6 (최근 30일)
Anuj Rekhy
Anuj Rekhy 2016년 6월 13일
답변: Star Strider 2016년 6월 13일
I have a 3D cascade plot. It has Amplitude Vs Frequency data on X and Y axis. It has amplitude on Z axis. I want to create an animation where the evolution of data on X Y axis is updated slowly in the Z direction as the time progresses.
  댓글 수: 2
Walter Roberson
Walter Roberson 2016년 6월 13일
Which plot call did you use to create the 3D cascade plot?
Anuj Rekhy
Anuj Rekhy 2016년 6월 13일
I used the surf(X,Y,Z) to get the plot. Now I want to animate it with time.

댓글을 달려면 로그인하십시오.

답변 (2개)

Star Strider
Star Strider 2016년 6월 13일
See if modifying this code snippet with your surf call and data does what you want:
[X,Y] = meshgrid(linspace(-5, 5, 50)); % Create Mesh Data
fcn = @(x,y,k) k*x.^2 + y.^2; % Function To Plot (Vary Sign Of ‘x’)
v = [1:-0.05:-1; -1:0.05:1]; % Multiplier For ‘x’
for k1 = 1:2 % One Cycle For ‘Up’, One FOr ‘Down’
for k2 = v(k1,:) % Select A Direction From ‘v’
surfc(X, Y, fcn(X,Y,k2)) % Draw Surface
axis([-5 5 -5 5 -30 50]) % Set ‘axis’ For All Plots
drawnow % Draw Plot
pause(0.1) % Create Evenly-Timed Steps For Animation
end
end
You will have to experiment with it to get the result you want.

KSSV
KSSV 2016년 6월 13일
h.fig = figure ;
h.ax = handle(axes) ; %// create an empty axes that fills the figure
h.surf = handle( surf( NaN(2) ) ) ; %// create an empty "surface" object
%Display the initial surface
set( h.surf , 'XData',X , 'YData',Y , 'ZData',Z )
for i = 1:n
% update surface, load the data
h.surf.ZData = Z ;
end
  댓글 수: 4
Anuj Rekhy
Anuj Rekhy 2016년 6월 13일
편집: Anuj Rekhy 2016년 6월 13일
Only X is constant in all the plots there are 50 plots for example. Then both the Y and Z values are changing in every frame and needs an update.
I am attaching a reference figure for your understanding of the problem. Here Time is Y data and the amplitude is Z data and X data is Frequency that is constant throughout.
I wanted to show time evolution of such a graph - such that it starts from zero and goes till 25 sec.
Walter Roberson
Walter Roberson 2016년 6월 13일
for i = 1:n
Z = ... new data
set(h, 'ZData', Z);
drawnow()
end

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Animation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by