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

22 ビュー (過去 30 日間)
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 件のコメント
darova
darova 2019 年 7 月 24 日
You have only one matrix 3D?
BananaBandana
BananaBandana 2019 年 7 月 24 日
yes, one threedimensional Matrix

サインインしてコメントする。

採用された回答

darova
darova 2019 年 7 月 24 日
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 件のコメント
darova
darova 2019 年 7 月 24 日
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 2019 年 7 月 24 日
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

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by