3D Temperature distribution plot

39 Ansichten (letzte 30 Tage)
Joe Check
Joe Check am 17 Aug. 2020
Bearbeitet: jonas am 18 Aug. 2020
Hi there,
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:
%Plot results
kmin = 1;
kmax = 101;
imin = 1;
imax = 21;
[kk,ii] = meshgrid(kmin:kmax,imin:imax);
mesh(kk,ii,t);
xlabel('Y-Coordinate (mm)')
ylabel('X-Coordinate (mm)')
zlabel('Temperature (deg)')
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.
  2 Kommentare
jonas
jonas am 17 Aug. 2020
Bearbeitet: jonas am 17 Aug. 2020
You could use permute() to get a 21x101x721 matrix where each layer is a crank angle. However, more importantly, are you sure you want to have 721 surface plots in the same graph?
Joe Check
Joe Check am 17 Aug. 2020
Hi Jonas,
Thanks for your message.
For the time being let's say that I want to see a single surface plot showing the temperature distribution at the crank angle of 175 degrees, how do I do that?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

jonas
jonas am 17 Aug. 2020
Bearbeitet: jonas am 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
surf(A(:,:,i));
If you want to plot a single coordinate over crank angles, then you could use
out = squeeze(A(x,y,:))
  2 Kommentare
Joe Check
Joe Check am 17 Aug. 2020
Thank you so much for your input Jonas. I'm finally able to see what I wanted.
One last question though, would it be possible to add a few more layers to a single graph? Say I wanted to see the distribution in a range from 1 to 5 degress or 90 to 120 etc. Would it be possible?
jonas
jonas am 18 Aug. 2020
Bearbeitet: jonas am 18 Aug. 2020
Sure, you can have multiple surface objects in the same graph. I would use a for-loop to plot different layers. Remember to use "hold on" on the axes. There is a big risk the plot will be messy.
figure
surf(peaks); hold on
surf(peaks+10)
surf(peaks+20)
Another option is to use a flat surface plot, like pcolor() or contourf(), to avoid intersections between different surface objects. You can change the z-value to some arbitrary offset.
for i = 1:5
h(i) = pcolor(peaks);hold on
set(h(i),'zdata',repmat(i*5,size(peaks,2),size(peaks,1)),'facealpha',0.8) %first argument of repmat (i*5) is a variable offset
end
set(h,'facealpha',0.8) %if you want transparent surfaces
view(3) %view in 3d

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by