配列の3次元プロット
9 views (last 30 days)
Show older comments
配列 a(48,48,72)に入っているデータを3次元x,y,z 軸上にプロットしたい。
中心(0,0,0),-24<=x<=24,-24<=y<=24,-36<=z<=36,としてa(1,1,1)に収納されている数値に対応したプロットを(x,y,z)=(-24,-24,-36)にプロットしたい。収納されている数値の大きさによってカラーリングも行いたい。
得られるプロットのイメージは図のような感じです。(これがカラーリングされている)
2 Comments
Accepted Answer
Hernia Baby
on 24 Jun 2021
概要
scatter3で大丈夫ですが、もう一工夫いります。
おそらくそのままやると上手く図示できないか、直線になるのではないでしょうか?
meshgridで立体的なプロットが可能となります。
せっかくなのでお遊びで四角い枠も作ってみましょう。
四角い枠を作る
clear,clc,close all;
vert = [0 0 0;1 0 0;1 1 0;0 1 0;0 0 1;1 0 1;1 1 1;0 1 1];
vert(vert==1)=40;
vert(vert==0)=-40;
fac = [1 2 6 5;2 3 7 6;3 4 8 7;4 1 5 8;1 2 3 4;5 6 7 8];
patch('Vertices',vert,'Faces',fac,...
'FaceVertexCData',hsv(6),'FaceColor','r','FaceAlpha',.01)
view(3)
axis vis3d
hold on
配列の3次元プロット
今回は刻み幅1の点とします。色は適当です。まずは座標。
x = -24:24;
y = -24:24;
z = -36:36;
このまま描画すると直線になります。
[X,Y,Z] = meshgrid(x,y,z);
最後にサイズと色を指定して、軸も消して完成です。
s = 1;
M = abs(cos(2*pi*X(:)/48)+sin(2*pi*Y(:)/48)+sin(2*pi*Z(:)/72));
scatter3(X(:),Y(:),Z(:),s,M);
ax = gca;
ax.XAxis.Visible ='off';
ax.YAxis.Visible ='off';
ax.ZAxis.Visible ='off';
1 Comment
More Answers (0)
See Also
Categories
Find more on 表面プロットとメッシュ プロット in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!