Matlab optimized slice plot

17 views (last 30 days)
Steffen B.
Steffen B. on 8 Mar 2024
Answered: Arnav on 8 Nov 2024 at 10:02
Hello,
I have a question regarding the slice plot in matlab.
I solve the temperature field in a cube domain, depending on convective and or temperature boundary conditions. So far no problem, but the result plot is not really nice. When I use the slice function I get this:
But I want a plot like this:
With this shape:
A Cube with a cut out quarter, to present the temperature change over time.
Is it even possible to create such a plot, or is another plot function a better choice?
In addition, a small second question. Can I plot only the temperature isolines on the surfaces?
The slice related code I used is following:
f2 = figure(2);
movegui(f2,[1200 100]);
fontSize=20;
fontSize2=16;
f2.Position(3:4) = [1080 780];
% 3D
h=slice(x,y,z,T,[0 L/2],[H],[B/2 B],'cubic');
set(gca,'FontSize',fontSize)
set(gca,'YDir','normal')
colormap(jet)
shading interp
brighten(jet,.5)
set(h,'edgecolor','black','facealpha',1,'linewidth',1)
xlabel('x-Direction x/ m','FontSize', fontSize)
ylabel('z-Direction z/ m','FontSize', fontSize)
zlabel('y-Direction y/ m','FontSize', fontSize)
axis([0 B 0 L 0 H])
view(30,30)
rotate(h,[1,0,0],-90);
hold on
cb=colorbar("northoutside");
set(cb,'FontSize',fontSize);
caxis([70, 300]);

Accepted Answer

Arnav
Arnav on 8 Nov 2024 at 10:02
You can plot a solid with its surface denoting its temperature by using the following function:
function PLOT(X,Y,Z,T)
X_flat = X(:);
Y_flat = Y(:);
Z_flat = Z(:);
T_flat = T(:);
k = boundary(X_flat, Y_flat, Z_flat, 1);
figure;
trisurf(k, X_flat, Y_flat, Z_flat, T_flat, 'FaceColor', 'interp', 'EdgeColor', 'none');
colormap jet;
colorbar;
xlim([-10 10]);
ylim([-10 10]);
zlim([-10 10]);
title('3D Solid with Temperature Gradient on Boundary');
end
Here, boundary function is used to extract the boundary of the solid and trisurf function is used to plot the triangulated surface.
You can learn more about the functions here:
Assuming a radial temperature profile for the cube,
x = linspace(-5, 5, 30);
y = linspace(-5, 5, 30);
z = linspace(-5, 5, 30);
[X, Y, Z] = meshgrid(x, y, z);
T = sqrt(X.^2 + Y.^2 + Z.^2);
The quadrant can be cut out as shown below:
mask = ~(X > 0 & Y > 0);
X = X(mask);
Y = Y(mask);
Z = Z(mask);
T = T(mask);
The output figure of the PLOT function is shown below:
To plot temperature isolines on the surface of the cube, you can use a custom colormap instead of jet colormap. For example, colour can be set to black in the neighbourhood of every temperature value that is a multiple of 5 otherwise white.

More Answers (0)

Products


Release

R2016b

Community Treasure Hunt

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

Start Hunting!