[英]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.