3D Temperature distribution plot
57 views (last 30 days)
I'm working on a tribology problem which looks into the temperature distribution in a thin oil film between a piston ring and a cylinder bore. I wrote a code which incorporates the finite difference method to give me the output of how the temperature varies throughout the film thickness with different crank angles (engine strokes).
My code works fine however I'm not quite sure how to plot my results correctly. I and my supervisor chose matlab to generate nice 3D plots of the temperature distribution however I don't have enough matlab experience to do it correctly and I don't understand much having read the long descriptions in the Matlab documents. (The original version of my code was written in Fortran).
The problem is that all my temperature values are stored in a 3D matrix of the size (721 x 21 x 101).
Where the number 721 is a number of degrees showing the engine crank angle going from 1 to 721. 21 is the number of grid points in the x direction and 101 is the number of grid points in the y direction.
When I wrote a first version of my code which didn’t include the crank angle part I just ended up with a 2D temperature matrix t of the size of 21 x 101 then I was able to use the meshgrid and mesh commands to do the plots and my code looked like the following:
kmin = 1;
kmax = 101;
imin = 1;
imax = 21;
[kk,ii] = meshgrid(kmin:kmax,imin:imax);
Now I don't know how to deal with this big 3D matrix t which stores 721 pages of seperate 2D temperature matrices.
Do I need to use a for-loop to loop through the crank angles?
Any help would be greatly appreciated.
jonas on 17 Aug 2020
Edited: jonas on 17 Aug 2020
It is convenient to have the variable you want to plot as layers in your 3d data. In other words you want a XYZ matrix but you have a ZXY. Use permute to rearrange your data, A
A = permute(A,[2,3,1]);
then you can easily plot the i'th layer as
If you want to plot a single coordinate over crank angles, then you could use
out = squeeze(A(x,y,:))