Mean calculation from nxm matrices using nxm index matlab

2 次查看(过去 30 天)
I have daily flow data from 400 gauging stations.The length of the flow data is about 20 years. I want to calculate 20-yrs averages flow for each month of the year using for-loop in matlab. Please see the attachment. I just want to average flow-data(flow_data.PNG) using the corresponding identical index value (index.PNG).
thanks
  1 个评论
Stephen23
Stephen23 2018-3-12
@Abaye Getahun Abebe: screenshots of data are useless for us. We cannot import screenshots of data, we cannot search screenshots of data, we cannot test our code on screenshots of data.
If you want help with this then delete the screen shots and upload some sample data files.

请先登录,再进行评论。

回答(2 个)

Prajit T R
Prajit T R 2018-3-15
Hi Abaye I understand that you wish to obtain the monthly mean flow for the data you have provided. Assuming that Month_data.mat contains the information of month v/s gauging station, I have written a code to find the average flow for each month. I'm not sure if this is what you are looking for, but hope this helps.
load('flow_data.mat');
load('Month_data.mat');
mean_month=[];
for i=1:12
cur_month=find(Month_data==i);
mean_month(end+1)=mean(flow_data(cur_month));
end
mean_month
The variable cur_month returns indices of all occurrences of the particular month, and we filter the flow data using these indices to obtain the average.
Cheers

Andrei Bobrov
Andrei Bobrov 2018-3-15
out = [(1:12)',accumarray(Month_data(:),flow_data(:),[],@mean)];

类别

Help CenterFile Exchange 中查找有关 Whos 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by