八度存储每个循环的迭代值

问题描述 投票:0回答:0

我的一个项目需要你的帮助。我在 Octave 中使用 for 循环来计算某些数据的均值、标准差和方差,并将此信息存储在称为度量的矩阵中。数据由 19 列和 15000 行组成,存储在 epochs 变量中。我的代码是这样的:

# Preallocate memory for the epoch data
epochs = zeros(15000, 19);
# Preallocate memory for metrics
metrics = zeros(3, 19);

for i = 1:20
  start_idx = (i - 1) * epoch_length + 1;
  end_idx = start_idx + epoch_length -1;
  epochs(:,i) = patient1(start_idx:end_idx);
  
  # Calculate the mean, standard deviation, and variance for multiple EEG channels
  meanValue = mean(epochs,1); # mean of all EEG channels
  stdValue = std(epochs,0,1); # standard deviation of all EEG channels
  varValue = var(epochs,0,1); # variance of all EEG channels


  # Collect metrics in a single matrix
  metrics(1,:) = meanValue;
  metrics(2,:) = stdValue;
  metrics(3,:) = varValue;

我遇到的问题是这段代码只在历元和度量矩阵中存储最后一次迭代的数据,而我希望代码产生 20 个不同的历元和度量矩阵,每个矩阵都包含值20 次迭代中的每一次。

你能帮帮我吗? 提前致谢

for-loop matrix iteration octave metrics
© www.soinside.com 2019 - 2024. All rights reserved.