3D Matrix to create 3D graphic

My goal:
I have a 3D matrix with 50x50x50 (x,y,z). This Matrix creates a fixed dice. In each point(x,y,z) I have a value. Those values combined should create the colors. Just for interest, the idea behind a lot of high values f.e. are red colored and form to a shape, because of their position in the dice (x,y,z). lower values f.e. are blue and are all over the place. In fact, they dont form to a shape.
I was reading before a couple of blogs about that topic and havent found any right answers for me. May be I overread somewhere a good one. Its possible=)
Thats why thats not how I want it:
If I transfer my data to multiple 2D layers, which works out, and I use a movie, I get a 2D graphic with colors.Its not the idea!I tried mesh. It is just for 2D matrix.plot3 doesnt create colors!
If there is a possibility how its done, that would help me a lot. I saw from other papers that it is somehow possible. They didnt add any code on it. Thanks in front for anyone with good ideas=)))

1 comentario

felix
felix el 26 de En. de 2011
hmm,...I have a variable with 50x50x50 dimension, which is width, length and depth and looks like a dice. Each point of it,for example 1x1x1, 1x1x2 or 1x2x1, has a value. I want to plot this variable with its dimension into a 3D graphic and the values should colormap it.
scatter3() needs x,y,z as functions the way I understood its describtion. I dont have it. Is there still a way I can plot my variable?=)

Iniciar sesión para comentar.

 Respuesta aceptada

felix
felix el 26 de En. de 2011
Editada: Ned Gulley el 14 de Feb. de 2014

0 votos

Hmm... I have a variable with 50x50x50 dimension, which is width, length and depth and looks like a dice. Each point of it,for example 1x1x1, 1x1x2 or 1x2x1, has a value. I want to plot this variable with its dimension into a 3D graphic and the values should colormap it.
scatter3() needs x,y,z as functions the way I understood its description. I dont have it. Is there still a way I can plot my variable?=)

4 comentarios

Walter Roberson
Walter Roberson el 26 de En. de 2011
Editada: Walter Roberson el 30 de Dic. de 2020
ballsize = 5;
[xx, yy, zz] = meshgrid(1:50,1:50,1:50);
scatter3(xx(:),yy(:),zz(:),ballsize, YourMatrix(:))
This will draw a small ball at each location in the cube, and the ball will be colored according to the value of your matrix.
You could increase the ball size to approximate the size of the cubic cells, if you want each sub-cube to be filled, but if you do so you will quickly find that you cannot see "into" the cube.
If you need to be able to see "into" the cubic array, with the cubes not obscuring each other, you would have to use an Alpha (transparency) matrix. Alpha transparency is like looking through colored glass: unless it is very good glass, it doesn't take many layers before the insides are obscured.
This is a fundamental difficulty with 4D data: seeing "inside" of it. You can take slice()'s of it, or you can use isosurfaces, but there is not a lot else you can do directly in matlab.
You may wish to refer to the File Exchange contribution sliceomatic http://www.mathworks.com/matlabcentral/fileexchange/764
deqwwe cheng
deqwwe cheng el 30 de Mzo. de 2017
great
Victor Zhou
Victor Zhou el 30 de Dic. de 2020
awesome!
Gideon Mufumbi
Gideon Mufumbi el 12 de En. de 2021
Great. Helped me a lot as I am dealing with a number of 51x51x11 matrices.

Iniciar sesión para comentar.

Más respuestas (3)

Sean de Wolski
Sean de Wolski el 25 de En. de 2011

0 votos

I really don't understand what you're aiming for. Do you want a colormap based on height?
If so you could use multiple calls to:
patch
with a varying color each time. The color could be based on the result from some function of:
[xx, yy, zz] = meshgrid(1:50);
Or you could make your movie in true color using the 4th dimension, also based on the above call to meshgrid.
doc immovie

1 comentario

felix
felix el 25 de En. de 2011
I want a colormap based on my values. my height is already given by z-axis.=) i have to go with smth like 4th dimension,thats right!!i will try the 4th dimension meshgrid example.

Iniciar sesión para comentar.

Walter Roberson
Walter Roberson el 25 de En. de 2011

0 votos

I'm wondering if you are looking for scatter3() ??

1 comentario

felix
felix el 25 de En. de 2011
i just looked it up.sounds like a good idea. thx, i will try that too.=)

Iniciar sesión para comentar.

Sean de Wolski
Sean de Wolski el 26 de En. de 2011

0 votos

What doesn't work about this?
[xx yy zz] = meshgrid(1:5)
scatter3(xx(:),yy(:),zz(:),20,sortrows(repmat([1 0 0; 0 0 1; 0 1 0; .5 0 .5; .5 .5 0],25,1)))
You have a numerical function zz(xx,yy).

3 comentarios

Walter Roberson
Walter Roberson el 26 de En. de 2011
You don't use the value of the matrix, Sean, but you do put in a color table in the color field of scatter3(). Felix does not have a 3D color for each point: he has a single value for each point. Fortunately, the color parameter of scatter3() can also take an array of values that are interpolated into the color map. If that is being implied, though, then the only difference compared to my comment in the prior answer is the unimportant detail of the exact parameters provided to meshgrid()
Sean de Wolski
Sean de Wolski el 26 de En. de 2011
Our answers crossed paths last night (Yours wasn't submitted when I started), Walter; otherwise I probably would've added to yours (since the biggest contribution was saying that what he has is a function). It's not totally clear still what Felix wants; it would be nice if he could show us a template from paint or something. Hopefully between all of these samples he'll be able to figure something out!
felix
felix el 27 de En. de 2011
thx, a lot. I have tried the ball example and my datas where showing up in the plot. I have tried another example from that link:http://www.mathworks.com/matlabcentral/fileexchange/4927-vol3d-m-vol3dtool-m , which worked great.
First loading up and the code I used to have a good picture was:
h = vol3d('cdata',mydata,'texture','2D');
view(3);
vol3d(h);
alphamap('decrease');
To show you what I meant I would like to show the two pictures I have got, when I used both examples. But somehow I cannot load them up. As I read through your helpfully answers, Walter got my idea perfectly. Each point one value. 50x50x50 are my dimensions. Now I will try the sliceomatic and see how that goes.

Iniciar sesión para comentar.

Categorías

Más información sobre Color and Styling en Centro de ayuda y File Exchange.

Productos

Preguntada:

el 25 de En. de 2011

Comentada:

el 12 de En. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by