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-16 09:23:58 浏览: 80
meanwind051060.zip_wind speed_实测风速数据_数据评估_风速数据_风速数据处理
5星 · 资源好评率100%
在你的代码中,每次迭代内层的循环时,你都会将计算结果存储在同一个变量中(例如 `mean_power(j,:)`、`std_power(j,:)` 等)。这导致了每次迭代结束后,这些变量的值被覆盖为当前迭代的结果。因此,最终的 `winddata` 数组中每行的数据都相同。
为了解决这个问题,你需要为每次迭代创建一个新的变量来存储结果。可以通过在外层循环之前初始化这些变量为零矩阵,并在内层循环中使用索引 `j` 来存储结果。修改后的代码如下所示:
```matlab
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];
```
这样修改后,每次迭代内层循环时,对应的变量会被正确地存储,并且最终的 `winddata` 数组将包含正确的数据。
阅读全文