how to plot using the slice function the last row and column of a 3 matrix?
5 次查看(过去 30 天)
显示 更早的评论
Hello, guys
I am trying to do the slicing of a 3d matrix, however I notice that the slice function during the plot do not show us the last column and row as we can see in the following code:
Is there a way to plot all the value of a 3 matrix during the slicing?
Thank you
Best regards
code:
clear all
clc
a=randi(5,3,3,3);
slice(a,1,[ ],[ ])
1 个评论
回答(1 个)
Adam Danz
2023-3-31
编辑:Adam Danz
2023-3-31
The syntax slice(V,xslice,yslice,zslice) plots surface using the vertex data in V at slices specifed by the 2nd, 3rd, and 4th arguments. Vertices define the edges of each face. Along a single dimension, a single face has two vertices so along a single dimension you will have a number of face equal to one minus the number of vertices.
Take this reproducible example that plots the faces of a 4x4x4 array along the first slice of the x-axis. It also adds a colorbar so we can see how the data maps to the colors.
rng(6) % for reproducibility
a=randi(5,4,4,4);
slice(a,1,[ ],[ ])
colormap(jet(10))
colorbar
The colors in the bottom row of the surface are defined by
a(:,1,1)
where 5 is red, 2 is blue, 5 is red, and the next face, if there was one, would be dark blue.
The colors in the middle row of the surface are defined by
a(:,1,2)
where 5 is red, 3 is mint green, 5 is red, and the next face, if there was one, would be red.
The colors at the top row of the surface are defined by
a(:,1,3)
where 2 is blue, 4 is yello, 3 is mint green, and the next face, if there was one, would be yellow.
In summary, the plot is produced again below and the vertices of the bottom row are numbered. If you interpolate the FaceColor, you can see the last edge of the vertices effet the colors.
figure
tiledlayout(1,2)
nexttile()
slice(a,1,[ ],[ ])
colormap(jet(10))
colorbar
text([1 1 1 1]-.2, [1 2 3 4], [1 1 1 1], string([1,2,3,4]),'FontSize', 14)
axis square
title('Flat')
nexttile()
h = slice(a,1,[ ],[ ]);
h.FaceColor = 'interp';
colormap(jet(10))
axis square
title('Interpolated')
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Distribution Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!