n行の行列があり、それぞれに 3 つの座標 (x、y、z) が含まれているとします。MATLAB で 100 セットのポイントごとに標準偏差を計算したいと考えています。たとえば、最初の 100 個の x 座標に を適用std
し、次に y 座標と z 座標に同じように適用します。最終的には、100 ポイントごとに x、y、z の値のセットが 1 つあります。それ、どうやったら出来るの?
質問する
5052 次
1 に答える
2
私はこれを行います:
M = randn(120,3); % substitute this for the actual data; 3 columns
N = 100; % number of elements in each set for which std is computed
cols = size(A,1);
for n = 1:ceil(cols/N)
row_ini = (n-1)*N+1;
row_fin = min(n*N, cols); % the "min" is in case cols is not a multiple of N
std(A(row_ini:row_fin,:))
end
速度が問題になる場合、「for」ループはおそらくベクトル化できます。
編集: すべての結果を 3 列の行列に格納する場合は、次のように「std」行を変更して初期化を追加するだけです。
M = randn(120,3); % substitute this for the actual data; 3 columns
N = 100; % number of elements in each set for which std is computed
cols = size(A,1);
n_max = ceil(cols/N);
result = repmat(NaN,ceil(cols/N),3); % initialize
for n = 1:n_max
row_ini = (n-1)*N+1;
row_fin = min(n*N, cols); % the "min" is in case cols is not a multiple of N
result(n,:) = std(A(row_ini:row_fin,:));
end
于 2013-07-16T10:50:43.930 に答える