matlab 中的 4 维图
4 dimensional plot in matlab
我正在尝试使用我的 4 维数据在 Matlab 中创建绘图。数据看起来像 [x,y,z,d],其中 x、y 和 z 是对象的坐标,"d" 是强度。我尝试映射数据并仅考虑 [x,y,d] 并进行等高线或冲浪,但为此 "d" 应该是一个矩阵。我也用过 plot3 但它看起来不太好或不像轮廓。知道如何以一种好的方式绘制它吗?
以下是数据示例:
1.2500000E-02 1.2500000E-02 1.2500000E-02 1.054474998136970E-002
1.2500000E-02 1.2500000E-02 3.7500001E-02 1.348833743199940E-003
1.2500000E-02 1.2500000E-02 6.2500000E-02 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 8.7499999E-02 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.1125000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.1375000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.1625000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.1875000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.2125000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.2375000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.2625000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.2875000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.3125000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.3375000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.3625000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.3875000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.4125000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.4375000 7.452120128176466E-006
1.2500000E-02 1.2500000E-02 0.4625000 2.235636038452940E-005
1.2500000E-02 1.2500000E-02 0.4875000 4.471272076905880E-005
1.2500000E-02 1.2500000E-02 0.5125000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.5375000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.5625000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.5875000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.6125000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.6375000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.6625000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.6875000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.7125000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.7375000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.7625000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.7875000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.8125000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.8375000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.8625000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.8875000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.9125000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.9375000 7.824726134585290E-004
1.2500000E-02 1.2500000E-02 0.9625000 9.657947686116700E-003
1.2500000E-02 1.2500000E-02 0.9875000 3.128400029808481E-002
1.2500000E-02 3.7500001E-02 1.2500000E-02 1.028392577688352E-003
谢谢
假设我们可以将 [x,y,z,T]
形式的矩阵转换为 3 个向量 X
、Y
、Z
和 3-D 矩阵 T
,同时T(ii,jj,kk)
对应 X(ii)
, Y(jj)
和 Z(kk)
.
不可能按原样绘制这样的字段,最接近观察者的可视化数据将隐藏其余部分,我们可以绘制这样的字段的一个子集,我们称之为 slice虽然不是肉但一定是飞机
在我的代码中,假设 slice 被定义为函数 z=f(x,y)。
在第一部分中,我定义了 X
、Y
、Z
向量和场 T
,其强度等于到 [0 0 0]
位置的距离。
然后我创建 slice 并使用封装函数 getTvalue
我计算适当的强度。
getTvalue
interpolates T(z)
dependence from the mesh and calculate the value for given Z.
然后我使用 surf
绘制 切片 以显示几何形状(前 3 个参数),第四个代表颜色 - 在我们的例子中是强度。
function[]=plot4d()
clc,close all
% Define the mesh
N=21;
X=-1:1/(N-1):1;
Y=X;
Z=X;
M=size(X,2);
% Define intensity matrix
T=zeros(M,M,M);
for ii=1:M
for jj=1:M
for kk=1:M
T(ii,jj,kk)=sqrt((X(ii))^2+(Y(jj))^2+(Z(kk))^2);
end
end
end
for ii=1:M
for jj=1:M
SliceZ(ii,jj)=X(ii)+(Y(jj)^2); % This is the SLICE FUNCTION, here (z=x+y^2)
% Calculate T value for (ii,jj) position using Z mesh, T values and actual Z position)
SliceT(ii,jj)=getTvalue(ii,jj,Z,T,SliceZ(ii,jj));
end
end
% Plot surface in range of X and Y, elevation defined by SliceZ and colour defined by SliceT without lines
surf(X,Y,SliceZ,SliceT,'linestyle','none')
% Plot the cross locating [0 0 0] point
line('xdata',[-1 1],'ydata',[0 0],'zdata',[0 0])
line('ydata',[-1 1],'xdata',[0 0],'zdata',[0 0])
line('zdata',[-1 1],'ydata',[0 0],'xdata',[0 0])
axis equal
% plot4d ends here
%% Nested functions:
function[Tvalue]=getTvalue(xi,yj,Zvector,Tmatrix,Zvalue)
% Test if the actual slice position (Zvalue) is inside the mesh (Zvector)
if Zvalue>max(Zvector)||Zvalue<min(Zvector)
% If not, return NaN and process to next iteration
Tvalue=nan;
return
end
M=max(size(Zvector)); % get the size of Z mesh
Index=find(Zvalue<=Zvector,1) % find interval inside which the Zvalue is
% Test if the Zvalue is on the edge of mesh (Zvector)
if Index==M
% Zvalue is on the edge - return the edge value (it prevents the index overflow)
Tvalue=Tmatrix(xi,yj,M);
else
% Zvalue is inside the mesh (Zvector)
% calculate the slope of T(x,y,z)=k*z(x,y)+q dependence.
k=(Tmatrix(xi,yj,Index)-Tmatrix(xi,yj,Index+1))/(Zvector(Index)-Zvector(Index+1));
% calculate transposition of the dependence
q=Tmatrix(xi,yj,Index)-k*(Zvector(Index));
% calculate the actual value of T
Tvalue=k*Zvalue+q;
end
% End of nested function
我正在尝试使用我的 4 维数据在 Matlab 中创建绘图。数据看起来像 [x,y,z,d],其中 x、y 和 z 是对象的坐标,"d" 是强度。我尝试映射数据并仅考虑 [x,y,d] 并进行等高线或冲浪,但为此 "d" 应该是一个矩阵。我也用过 plot3 但它看起来不太好或不像轮廓。知道如何以一种好的方式绘制它吗? 以下是数据示例:
1.2500000E-02 1.2500000E-02 1.2500000E-02 1.054474998136970E-002
1.2500000E-02 1.2500000E-02 3.7500001E-02 1.348833743199940E-003
1.2500000E-02 1.2500000E-02 6.2500000E-02 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 8.7499999E-02 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.1125000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.1375000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.1625000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.1875000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.2125000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.2375000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.2625000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.2875000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.3125000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.3375000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.3625000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.3875000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.4125000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.4375000 7.452120128176466E-006
1.2500000E-02 1.2500000E-02 0.4625000 2.235636038452940E-005
1.2500000E-02 1.2500000E-02 0.4875000 4.471272076905880E-005
1.2500000E-02 1.2500000E-02 0.5125000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.5375000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.5625000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.5875000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.6125000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.6375000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.6625000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.6875000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.7125000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.7375000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.7625000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.7875000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.8125000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.8375000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.8625000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.8875000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.9125000 0.000000000000000E+000
1.2500000E-02 1.2500000E-02 0.9375000 7.824726134585290E-004
1.2500000E-02 1.2500000E-02 0.9625000 9.657947686116700E-003
1.2500000E-02 1.2500000E-02 0.9875000 3.128400029808481E-002
1.2500000E-02 3.7500001E-02 1.2500000E-02 1.028392577688352E-003
谢谢
假设我们可以将 [x,y,z,T]
形式的矩阵转换为 3 个向量 X
、Y
、Z
和 3-D 矩阵 T
,同时T(ii,jj,kk)
对应 X(ii)
, Y(jj)
和 Z(kk)
.
不可能按原样绘制这样的字段,最接近观察者的可视化数据将隐藏其余部分,我们可以绘制这样的字段的一个子集,我们称之为 slice虽然不是肉但一定是飞机
在我的代码中,假设 slice 被定义为函数 z=f(x,y)。
在第一部分中,我定义了 X
、Y
、Z
向量和场 T
,其强度等于到 [0 0 0]
位置的距离。
然后我创建 slice 并使用封装函数 getTvalue
我计算适当的强度。
getTvalue
interpolatesT(z)
dependence from the mesh and calculate the value for given Z.
然后我使用 surf
绘制 切片 以显示几何形状(前 3 个参数),第四个代表颜色 - 在我们的例子中是强度。
function[]=plot4d()
clc,close all
% Define the mesh
N=21;
X=-1:1/(N-1):1;
Y=X;
Z=X;
M=size(X,2);
% Define intensity matrix
T=zeros(M,M,M);
for ii=1:M
for jj=1:M
for kk=1:M
T(ii,jj,kk)=sqrt((X(ii))^2+(Y(jj))^2+(Z(kk))^2);
end
end
end
for ii=1:M
for jj=1:M
SliceZ(ii,jj)=X(ii)+(Y(jj)^2); % This is the SLICE FUNCTION, here (z=x+y^2)
% Calculate T value for (ii,jj) position using Z mesh, T values and actual Z position)
SliceT(ii,jj)=getTvalue(ii,jj,Z,T,SliceZ(ii,jj));
end
end
% Plot surface in range of X and Y, elevation defined by SliceZ and colour defined by SliceT without lines
surf(X,Y,SliceZ,SliceT,'linestyle','none')
% Plot the cross locating [0 0 0] point
line('xdata',[-1 1],'ydata',[0 0],'zdata',[0 0])
line('ydata',[-1 1],'xdata',[0 0],'zdata',[0 0])
line('zdata',[-1 1],'ydata',[0 0],'xdata',[0 0])
axis equal
% plot4d ends here
%% Nested functions:
function[Tvalue]=getTvalue(xi,yj,Zvector,Tmatrix,Zvalue)
% Test if the actual slice position (Zvalue) is inside the mesh (Zvector)
if Zvalue>max(Zvector)||Zvalue<min(Zvector)
% If not, return NaN and process to next iteration
Tvalue=nan;
return
end
M=max(size(Zvector)); % get the size of Z mesh
Index=find(Zvalue<=Zvector,1) % find interval inside which the Zvalue is
% Test if the Zvalue is on the edge of mesh (Zvector)
if Index==M
% Zvalue is on the edge - return the edge value (it prevents the index overflow)
Tvalue=Tmatrix(xi,yj,M);
else
% Zvalue is inside the mesh (Zvector)
% calculate the slope of T(x,y,z)=k*z(x,y)+q dependence.
k=(Tmatrix(xi,yj,Index)-Tmatrix(xi,yj,Index+1))/(Zvector(Index)-Zvector(Index+1));
% calculate transposition of the dependence
q=Tmatrix(xi,yj,Index)-k*(Zvector(Index));
% calculate the actual value of T
Tvalue=k*Zvalue+q;
end
% End of nested function