代码之家  ›  专栏  ›  技术社区  ›  JoL

如何将Z高度矩阵转换为笛卡尔坐标?

  •  0
  • JoL  · 技术社区  · 7 年前

    我在倍频程中运行了一个FEMM模拟,结果得到了一个非常大的矩阵,格式如下:

    resultMatrix =  0 90 120
                    0 80 110
                   10 80 100
    

    在正常的carthesian系统中,它看起来像这样

    result = [1, 1, 0;
              2, 1, 90;
              3, 1, 120;
              1, 2, 0;
              ...]
    

    我该怎么做呢?

    2 回复  |  直到 7 年前
        1
  •  2
  •   carandraug    7 年前

    你可能在计算xy坐标之前,所以你应该保持他们从以前,所以你不必重新计算他们现在。不过,你的答案是:

    octave:1> results = [0 90 120; 0 80 110; 10 80 100];
    octave:2> col1 = repmat ([1; 2; 3], [3 1]); # repeat matrix
    octave:3> col2 = ([1; 1; 1] .* [1 2 3])(:); # automatic broadcasting
    octave:4> coords = [col1 col2 results.'(:)]
    coords =
    
         1     1     0
         2     1    90
         3     1   120
         1     2     0
         2     2    80
         3     2   110
         1     3    10
         2     3    80
         3     3   100
    
        2
  •  2
  •   Tasos Papastylianou    7 年前

    在八度音阶中实现这一点最直接的方法是创建一个网格。

    [Xindices, Yindices] = ndgrid( 1:size(resultMatrix,1) , 1:size(resultMatrix,2) );
    

    这样就可以直接绘制曲面,如下所示:

    surface( Xindices, Yindices, resultMatrix );
    

    真正地

    result = [ Xindices(:), Yindices(:), resultMatrix(:) ];