How can I display a 3D image of a 10x10x10 matrix? Each cube has a value between 1-10.
5 次查看(过去 30 天)
显示 更早的评论
I have a 2D matrix s(10,10). So, there are 100 squares. Each square has a value between 1-10. So, I can display the matrix with imagesc(s) function. The image is like the following. s represents the bottom right. The squares in the below picture have values between 1 or 2
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1159493/image.jpeg)
Now I want to extend the matrix to 3D, which is s(10,10,10) and has 1000 cubes , each having a value between 1-10. How can I display it like the following image with each cube colored by their respective values?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1159498/image.jpeg)
0 个评论
回答(1 个)
Bjorn Gustavsson
2022-10-17
编辑:Bjorn Gustavsson
2022-10-17
You should be able to generate a figure like the cube you show by utilizing the slice-function. Something like this:
% Mocking up some 10x10x10 data
s10by10by10 = round(convn(10*rand(10,10,10),ones(2,2,2)/8,'same'));
% displaying with slice
slice(s10by10by10([1:end,end],[1:end,end],[1:end,end]),[1 11],[1 11],[1,11])
You might have to play around with the colour-map to get a nice display:
colorbar
cmp = jet(10);
colormap(cmp(randperm(size(cmp,1)),:)) % To get increased contrast between regions with similar values
HTH
7 个评论
Bjorn Gustavsson
2023-1-25
@MD MAHABUBUR ROHOMAN, yes, that might work. Just try, and read the help and documentation of slice to see what other modifications you might be interested in.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!