MATLAB: Plotting/visualizing results of a 3D heat diffusion equation

3d arrayfinite differenceheat diffusion equationMATLABmeshgridtemperature field visualization

Hey guys; I have been playing with this problem for a couple of days now. And I think now it's about time to get some help. 🙂
I have a 3D space (i.e. a room) with different dimensions as the width (W), depth (D) and height (H) of the room (Please refer to the attached image, named "geometry"). There is a heat source within the geometry somewhere near the right-back-floor intersection (the location of the heat source is NOT the focus of my question). I am solving the 3D heat diffusion equation to calculate the variation of the temperature within the room, due to the heat source, as the time progresses.
Number of discretization along W, D and H directions are NW, ND and NH, respectively. Therefore, I go ahead and create a 3D matrix for the temperature field with the dimension of Tn=(NH,NW,ND). Note that the first (NH), second (NW) and third (ND) arrays of this matrix are representing height (rows), width (column) and depth (page) of the room (considering the fact that our 3D matrix is starting at point O in the schematic, as per MATLAB convention for the 3D matrix).
I solve the equation using finite difference method (using some initial and boundary conditions) and the result of the temperature field is according to my expectation (based on the inspection of the temperature matrix, Tn). However, I am having difficulty plotting/visualizing the results. Can you help me plot the temperature field in a coordinate system with its origin at point M (refer to the attached image), its x axis lying in W direction, its y in D direction and its z in H direction??
You may recommend meshgrid. But I already tried that with no success. So, let's say I define the x and y and z as three vectors with dimension (1*NW), (1*ND) and (1*NH), respectively. Using [X,Y,Z]=meshgrid(x,y,z) outputs three 3D matrices X, Y and Z with dimensions that is not the same as the Tn. So, I am really stuck.
(My .m code is attached to this question for your reference)
Thanks in advace

Best Answer

Ok, Thanks KKSV for the help. However, here is a problem. The order of elements in the vectors X(:), Y(:) and Z(:) is not the same as the order of element when you vectorize Tn, that's why when you plot them, they do not match.
So, I had to write a nested loop to re-arrange the order of elements in Tn and store it in another vector called TT to make it match with the order of X(:), Y(:) and Z(:). (By 'order', I mean the way they are arranged)
Here is the nested loop attached to this post for your reference.
I am sure there is a better and more efficient way of doing this, but this is all I can do about it.
Related Question