【问题标题】:4 dimensional plot in matlabmatlab中的4维绘图
【发布时间】:2016-03-07 17:52:29
【问题描述】:

我正在尝试使用我的 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

谢谢

【问题讨论】:

  • 也许答案就在那里:stackoverflow.com/questions/28403655/…
  • 您能否将您的绘图描述为函数(z,d)=f(x,y)d=f(x,y,z)? In the first case you can use surf where z` 定义高度,d 描述颜色。在第二种情况下,您必须选择一个切片z=f(x,y) 并使用它来获取[z,d]=g(x,y)。我现在可以给你建议。
  • 你的变量是什么维度?您可以附加您用于plot 的代码和图像吗?它可能有助于理解数据。
  • 您粘贴的数据看起来不像它实际上定义了一个表面,对于相同的 x 和 y 值,您有多个 z 值。这是否描述了一个卷?
  • @Daniel 这意味着,数据表示,例如,体积中的温度。

标签: matlab multidimensional-array plot contour


【解决方案1】:

假设我们可以将[x,y,z,T] 形式的矩阵转换为 3 个向量 XYZ 和 3-D 矩阵 T,而 T(ii,jj,kk) 对应于 X(ii)Y(jj)Z(kk)

不可能按原样绘制这样的字段,最接近查看者的可视化数据将隐藏其余部分,我们可以绘制这样的字段的子集,我们称之为 slice 虽然它没有肉,一定是飞机。

在我的代码中,假设 slice 被定义为函数 z=f(x,y)。

在第一部分中,我定义了XYZ 向量和场T,其强度等于到[0 0 0] 位置的距离。

然后我创建 slice 并使用封装函数getTvalue 计算适当的强度。

getTvalue 从网格中插入 T(z) 依赖关系并计算给定 Z 的值。

然后我使用 surf 绘制 slice 以显示几何图形(前 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

【讨论】:

  • 答案对代码和/或解释的任何编辑都是开放的。
  • 实际上,由于XY 是索引iijj 的“函数”,您可以调整函数以将slice 当作一个球、圆环或任何其他形状您可以通过向量X(ii)Y(jj) 和矩阵Z(ii,jj) 定义。换句话说,切片必须由函数 f(x,y,z)=0 定义,并且取决于您如何定义 XYZT
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-26
  • 1970-01-01
  • 2012-08-17
  • 2017-01-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多