mean_power = zeros(32, size(winddata_1,2)); std_power = zeros(32, size(winddata_1,2)); kurt_power = zeros(32, size(winddata_1,2)); skew_power = zeros(32, size(winddata_1,2)); max_power = zeros(32, size(winddata_1,2)); min_power = zeros(32, size(winddata_1,2)); for i=1:95:size(winddata_1,1) for j=1:1:32 % 日出力均值 mean_power(j,:) = mean(winddata_1(i:min(i+95, size(winddata_1,1)),:)); % 日出力标准差 std_power(j,:)= std(winddata_1(i:min(i+95, size(winddata_1,1)),:)); % 日出力峰度 kurt_power(j,:)= kurtosis(winddata_1(i:min(i+95, size(winddata_1,1)),:)); % 日出力偏度 skew_power(j,:)= skewness(winddata_1(i:min(i+95, size(winddata_1,1)),:)); % 日出力最大值 max_power(j,:)= max(winddata_1(i:min(i+95, size(winddata_1,1)),:)); % 日出力最小值 min_power(j,:)= min(winddata_1(i:min(i+95, size(winddata_1,1)),:)); end end winddata=[mean_power,std_power,kurt_power,skew_power,max_power,min_power];为什么算出来每行数据相同
时间: 2024-04-21 07:22:29 浏览: 80
meanfunction_风速数据处理_风_风压_时程数据_风速时程_
5星 · 资源好评率100%
很抱歉,我之前的回答有误。在你的代码中,每次迭代内层循环时,你都会将计算结果存储在同一个变量中(例如 `mean_power(j,:)`、`std_power(j,:)` 等)。这导致了每次迭代结束后,这些变量的值被覆盖为当前迭代的结果。因此,最终的 `winddata` 数组中每行的数据都相同。
要解决这个问题,你需要为每个迭代创建一个新的变量来存储结果。你可以使用一个二维 cell 数组来存储这些结果。在外层循环之前,你可以初始化这个 cell 数组,并在内层循环中使用索引 `j` 来存储结果。修改后的代码如下所示:
```matlab
mean_power = cell(32, 1);
std_power = cell(32, 1);
kurt_power = cell(32, 1);
skew_power = cell(32, 1);
max_power = cell(32, 1);
min_power = cell(32, 1);
for i=1:95:size(winddata_1,1)
for j=1:1:32
% 日出力均值
mean_power{j} = mean(winddata_1(i:min(i+95, size(winddata_1,1)),:));
% 日出力标准差
std_power{j} = std(winddata_1(i:min(i+95, size(winddata_1,1)),:));
% 日出力峰度
kurt_power{j} = kurtosis(winddata_1(i:min(i+95, size(winddata_1,1)),:));
% 日出力偏度
skew_power{j} = skewness(winddata_1(i:min(i+95, size(winddata_1,1)),:));
% 日出力最大值
max_power{j} = max(winddata_1(i:min(i+95, size(winddata_1,1)),:));
% 日出力最小值
min_power{j} = min(winddata_1(i:min(i+95, size(winddata_1,1)),:));
end
end
mean_power = cell2mat(mean_power);
std_power = cell2mat(std_power);
kurt_power = cell2mat(kurt_power);
skew_power = cell2mat(skew_power);
max_power = cell2mat(max_power);
min_power = cell2mat(min_power);
winddata = [mean_power,std_power,kurt_power,skew_power,max_power,min_power];
```
这样修改后,每次迭代内层循环时,对应的变量会被正确地存储,并且最终的 `winddata` 数组将包含正确的数据。在最后,我们使用 `cell2mat` 函数将 cell 数组转换为普通的数值数组。
阅读全文