Borrar filtros
Borrar filtros

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

5 visualizaciones (últimos 30 días)
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?

Respuestas (1)

Bjorn Gustavsson
Bjorn Gustavsson el 17 de Oct. de 2022
Editada: Bjorn Gustavsson el 17 de Oct. de 2022
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 comentarios
MD MAHABUBUR ROHOMAN
MD MAHABUBUR ROHOMAN el 25 de En. de 2023
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 el 25 de En. de 2023
@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.

Iniciar sesión para comentar.

Categorías

Más información sobre Image Processing Toolbox en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by