How can I display a 3D image of a 10x10x10 matrix? Each cube has a value between 1-10.

조회 수: 2 (최근 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
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?

답변 (1개)

Bjorn Gustavsson
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
MD MAHABUBUR ROHOMAN
MD MAHABUBUR ROHOMAN 2023년 1월 25일
Hello!
If I have a matrix of 5x5x5, I should only change the [1 11] to [1 6] in the slice command?
Bjorn Gustavsson
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 CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by