繁体   English   中英

倍频程:如何将“ xy值\\ n”格式的测量值排列到矩阵中?

[英]octave: how to arrange measurement values in format “x y value\n” into a matrix?

我有一个测量数据。 它以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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM