Matrix 倍频程:如何以“格式”排列测量值;x y值\n“;变成矩阵?

Matrix 倍频程:如何以“格式”排列测量值;x y值\n“;变成矩阵?,matrix,octave,Matrix,Octave,我有测量数据。它以以下格式存储: xy值 x y value 64 4 2743 64 8 3531 64 16 4543 64 32 5222 64 64 5730 128 4 2778 128 8 3500 128 16 4657 etc 如何将其

我有测量数据。它以以下格式存储: xy值

  x         y      value

   64        4     2743
   64        8     3531
   64       16     4543
   64       32     5222
   64       64     5730
  128        4     2778
  128        8     3500
  128       16     4657
  etc
如何将其重新排列为矩阵格式

    y= 4    8    16   32   64
x=
64    2743 3531 4543 5222 5730
128   2778 3500 4657 …    …  
256   …    …    …    …    …
512   …    …    …    …    …

在倍频程中?

这里我假设你对x和y的每一个值的组合都有一个度量,否则我们无法创建一个矩阵。此外,x和y值的序列应该重复,就像您的示例一样

% raw data is in a matrix D
% Unique will tell us all the values in the order in which they appear
x = unique(D(:, 1));
y = unique(D(:, 2));
% Reshape can create a matrix from a vector in column-major order
d = reshape(D(:, 3), length(y), length(x))'; % note transpose

newData = [x d];
输出:

octave> D
D =

     64      4   2743
     64      8   3531
     64     16   4543
     64     32   5222
     64     64   5730
    128      4   2778
    128      8   3500
    128     16   4657
    128     32   4512
    128     64   7854
octave> y'
ans =

    4    8   16   32   64

octave> newData
newData =

     64   2743   3531   4543   5222   5730
    128   2778   3500   4657   4512   7854

我必须为缺失的(但已定义的)值添加零模式,并使用D=rowsort(D,2)对其进行排序;以前,但现在,这是可行的。非常感谢。