Filter löschen
Filter löschen

How can I plot a 3D matrix as a cube with different transparent colors for the values?

13 Ansichten (letzte 30 Tage)
Hello,
I have a 3D-Matrix consisting only of values 0,1,2 and 3. Is it possible to plot the matrix so it looks like a big, transparent rubic´s cube, where every value gets its own colour? Like imagesc(...) but only in 3D.
Thanks a lot!
  4 Kommentare

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

darova
darova am 24 Jul. 2019
Since you have matrix of 0,1,2,3 and don't have coordinates you can create them
Assume A - is you matrix (N x N x N)
% (:) - colon operator (make vector from matrix of length N*N*N)
[X,Y,Z] = meshgrid(1:N);
scatter3(X(:),Y(:),Z(:),5,A(:))
  3 Kommentare
darova
darova am 24 Jul. 2019
Create one cube using patch() (or fill3()) then copy it using for loop
clear,clc,cla
x1 = [1 1 1 1]'/2; % right wall
y1 = [1 1 -1 -1]'/2;
z1 = [1 -1 -1 1]'/2;
x2 = [1 1 -1 -1]'/2; % top wall
y2 = [-1 1 1 -1]'/2;
z2 = [1 1 1 1]'/2;
x3 = x2; % bottom wall
y3 = y2;
z3 = -z2;
X = [x1 x2 x3];
Y = [y1 y2 y3];
Z = [z1 z2 z3];
patch(X,Y,Z,'b')
alpha(0.5)
axis equal
I succeded
img.png
BananaBandana
BananaBandana am 24 Jul. 2019
Thanks!
it worked! But I realized that it takes a lot of time to process for a bigger matrix and therefore is probably is not useable for my case :( I will probably have to think of a different way to visualize it... but thats a different question

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by