Help with updating slice plot in for loop
8 views (last 30 days)
Show older comments
I am plotting 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-matrix, V, which is the temperature at each data point. The temperature changes over time so I am trying to create an animation using a for loop over time and drawnow.
The problem I have is that I cannot seem to access and change V. I need to implement something to effect of:
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)
set(h, V, Vnew)
drawnow
end
end
I then get an error that says "There is no V property on the Surface class."
A workaround I have is to re-plot the whole graph at each step but this is quite slow - any help would be hugely appreciated!
0 Comments
Answers (1)
Wick
on 2 May 2018
You just need to draw a new slice with the new V_new.
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
1 Comment
Adalric Leung
on 5 Jul 2020
Hi I'm want to acheive the same thing as the previous person where my block dimensions are:
x = -0.5:dx:0.5; % x-vector (cm)
y = -0.5:dy:0.5; % y-vector (cm)
z = -0.5:dz:0.5; % z-vector (cm)
My temperature matrix is given by a 4D matrix (in x, y, z, time) where the first 3 terms provide the temperature at that location, creating a 3D temperature matrix at a sepcific time. I want to plot the block with those dimensions and then represent the changes in temperature as a colour, but I'm unsure how to interpret the code you wrote since I"m still fairly new to MatLab. More specifically, would the "V" be the 3D temperature matrix at a specific point in time? How would I get the x,y, and z slices?
I've included the data for my 4D temperature matrix if it helps.
Thank you for your time.
See Also
Categories
Find more on Graphics Performance in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!