Mean calculation from nxm matrices using nxm index matlab

2 ビュー (過去 30 日間)
Abaye Getahun Abebe
Abaye Getahun Abebe 2018 年 3 月 12 日
回答済み: Andrei Bobrov 2018 年 3 月 15 日
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 Center および File ExchangeWhos についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by