How to view the temperature distribution in a section or a slice?OR plot 4D
Show older comments
I got the temperature distribution using the transient thermal model(from a .STL file,irregular shape) in the PDE toolbox and got coordinates of nodes and the temperature of each node.
How can I view the temperature distribution in a section or a slice?
I have tried interpolateSolution function,but it seems for stationary results,not suitable for thermal model.As for Sliceomatic,I do not know how to use it with many errors.
What I want to get is just like this:


the data as follows:
x=model.Mesh.Nodes(1,:)'; % x-coordinate of nodes
y=model.Mesh.Nodes(2,:)'; % y-coordinate of nodes
z=model.Mesh.Nodes(3,:)'; % z-coordinate of nodes
u= R1.Temperature(1,:)'; % temperature of nodes
Answers (1)
Maneet Kaur Bagga
on 3 Jan 2024
Hello,
As per my understanding, to visualize the temperature distribution in a section (slice) of an irregular 3D shape can be achieved using the "slice" function. This is useful for examining the internal temperature distribution at a particular plane within the domain.
Given the coordinates of the nodes and the temperature at each node please refer to the following steps below to a possible workaround to the problem:
- Create a 3D grid that covers the domain of the model to capture the details of the temperature distribution.
- Use "griddata" function to interpolate the temperature data from the irregular mesh onto the 3D grid.
- Display the temperature disribution on the slice through the 3D grid using "slice" function.
As you are working with transient results and want to visualize the temperature at a specific time step, please extract the temperature data "u" for that time step before performing the interpolation.
Please refer to the code below for reference.
% Assuming x, y, z, and u contain the node coordinates and temperature
F = scatteredInterpolant(x, y, z, u); % Create an interpolant function
% Define the limits and resolution of the grid
xlin = linspace(min(x), max(x), 100);
ylin = linspace(min(y), max(y), 100);
zlin = linspace(min(z), max(z), 100);
% Create the grid
[X, Y, Z] = meshgrid(xlin, ylin, zlin);
% Interpolate the temperature onto the grid
U = F(X, Y, Z);
% Choose the slice positions (modify as needed)
xslice = []; % Empty means no slice along X
yslice = []; % Empty means no slice along Y
zslice = mean(z); % Slice in the middle of the Z domain
% Create the slice plot
slice(X, Y, Z, U, xslice, yslice, zslice)
shading interp % Optional for smoother color transition
colorbar % To show the temperature scale
xlabel('X')
ylabel('Y')
zlabel('Z')
title('Temperature Distribution Slice')
For better understanding MATLAB Documentation is attached below:
Transient Thermal Results: https://www.mathworks.com/help/pde/ug/pde.transientthermalresults.html
slice function: https://www.mathworks.com/help/matlab/ref/slice.html
Hope this helps!
Categories
Find more on Structural Mechanics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!