Plotting 3D Animation from 4-D Data

Hi,
I'm trying to plot an animated 3D plot from some data that I've calculated. The matrix is a 4D matrix that is a function of x y z and time, where at each point, the temperature of that point is represented.
For example, in the sample values below, it can be seen that "val(:,:,1,1)" represents the temperatures at each coordinate of space in the x-y plane on the first z-plane and at the first point in time. Likewise, the values found in "val(:,:,2,1)" represent the temperatures at each coordinate of space in x-y plane for the SECOND z-plane at the first point in time. This continues until all the temperature values are displayed for each position in x, y, and z, at the first point in time. After which, the sequence repeats at "val(:,:,1,2)" which displays the temperatures at each x-y coordinate for the first z-plane but at the SECOND point in time.
Thank you for any help in advance.

2 Comments

Please use attachment button to attach the data
Sorry, I've reattached the file in the main question. Thank you!

Sign in to comment.

 Accepted Answer

Here is the start
clc,clear
load 4D_Data.mat
% initialization of surfaces
for j = 1:size(T_adi,3)
h(j) = surface(T_adi(:,:,j,1));
end
view(3)
% change data
for i = 1:size(T_adi,4)
for j = 1:size(T_adi,3)
set(h(j),'zdata',T_adi(:,:,j,i)+20*j)
end
pause(0.1)
i
end

3 Comments

Hi,
Thank you for your help with this. I'm so sorry, but unfortunately, I shiould have clarified and did not realize how to word what I was looking for.
I want to plot slices of a block with dimensions x,y,z and using a colour map to represent the temperature of the block, which is described by the 3D temperature matrix at each point in time (ie. 4D_Data(:,:,:,i)). The temperature changes over time so I am trying to create an animation using a for loop over time and drawnow. The block dimensions are provided below.
x = -0.5:0.1:0.5; % x_vector
y = -0.5:0.1:0.5; % y_vector
z = -0.5:0.1:0.5; % z_vector
And the sample code I found is:
if true
[X, Y, Z] = meshgrid([0 x], [0 y], [0 z]);
h = slice(X,Y,Z,V,xslice,yslice,zslice);
colorbar
for n = 1:tmax
Vnew = (function that determines the temperature at the next time step)
h = slice(X,Y,Z,Vnew,xslice,yslice,zslice);
drawnow
end
end
I'm unsure if "V" represents the 3D temperature matrix at a specific point in time, and how to interpret the x,y,z slices. Was hoping you could help me out with this.
Thank you for your time, and sorry again.
maybe this will be helpfull
load 4D_Data.mat
[m,n,k,l] = size(T_adi);
[x,y,z] = meshgrid(1:m,1:n,1:k);
for i = 1:size(T_adi,4)
slice(x,y,z,T_adi(:,:,:,i),[3 m-2],[3 n-2],[3 k-2])
% alpha(0.5)
pause(0.1)
end
Thank you, this is perfect!!!

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!