在MATLAB中计算海量数据均值的有效方法 [英] Efficient way to calculate mean for huge data in MATLAB

查看:189
本文介绍了在MATLAB中计算海量数据均值的有效方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有先前模拟的输出,其中有32872行和1000列.该行代表90年的每日数据,而该列代表90年的不同数据集.我想做的是分别计算每年的平均值和标准偏差.例如我在做什么:

I have an output from previous simulation where it has 32872 row and 1000 column. the row represents daily data for 90 years while the column represents different data sets for 90 years. What i want to do is calculate the mean and standard deviation for every year separately. For example what i am doing is :

%for year 1
a=mean2(RAINFALL(1:365,:));
b=std2(RAINFALL(1:365,:));

%for year 2
a=mean2(RAINFALL(366:730,:));
b=std2(RAINFALL(366:730,:));
.
.
.
.
%for year 90
a=mean2(RAINFALL(32508:32872,:));
b=std2(RAINFALL(32508:32872,:));

我所做的是我每年手动计算,因此我必须手动执行约90次.问题是我大约有100个这样的数据集.无论如何,我是否可以通过自动或使用循环或MATLAB中的任何其他函数来执行此操作,以简化此过程并将输出数据存储在一个矩阵中,例如:

What i did was i calculate manually each year so i have to do it manually for about 90 times. the problem is i have about 100 of data sets like this. Is there anyway that i can perform this via automatically or using loop or other any function in MATLAB to simplify this process and store the output data in one matrix such as:

这样我就不必手动进行操作了?我是MATLAB编程的新手,并希望MATLAB的专家可以向我提出如何有效解决此问题的想法.我非常感谢您的帮助,因为这是针对我的硕士论文项目. 谢谢

so that i don't have to do it manually? I am new to MATLAB programming and hope that experts in MATLAB can suggest me idea how to solve this efficiently. i really appreciate your help because this is for my masters dissertation project. Thank You

推荐答案

for循环可能会帮助您-

R = rand(32872,90); % replace this with your rainfall data
startyear = 2010; % according to your comments

% generate array indices
nod = 365*ones(90,1) ... % number of days in each year
    +(mod((startyear:(startyear+89))',4)==0);
ind(:,2) = cumsum(nod);
ind(:,1) = [0; ind(1:end-1,2)]+1;

% find stats
a = zeros(90,1);
b = zeros(90,1);
for ii = 1:90
    yeardata = R(ind(ii,1):ind(ii,2),:);
    a(ii) = mean2(yeardata);
    b(ii) = std2(yeardata);
end

请注意,此处的棘手问题是正确处理the年.

Note that the tricky point here is to handle the leap years properly.

如果您没有包含mean2std2的图像处理工具箱,则

If you don't have Image Processing Toolbox, which includes mean2 and std2, then

    a(ii) = mean(yeardata(:));
    b(ii) = std(yeardata(:));

这篇关于在MATLAB中计算海量数据均值的有效方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆