0

假设我有一个包含n行的矩阵,每行包含三个坐标(x、y 和 z)。我想计算 MATLAB 中每 100 个点的标准差。例如,对于我应用的前 100 个 x 坐标std,然后应用相同的 y 和 z 坐标,依此类推……最终,我每 100 个点都有一组 x、y 和 z 值。我怎么做?

4

1 回答 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”循环可能会被矢量化。

编辑:如果要将所有结果存储在三列矩阵中,只需修改“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 回答