Mean calculation from nxm matrices using nxm index matlab

2 Ansichten (letzte 30 Tage)
Abaye Getahun Abebe
Abaye Getahun Abebe am 12 Mär. 2018
Beantwortet: Andrei Bobrov am 15 Mär. 2018
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 Kommentar
Stephen23
Stephen23 am 12 Mär. 2018
@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.

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Prajit T R
Prajit T R am 15 Mär. 2018
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 am 15 Mär. 2018
out = [(1:12)',accumarray(Month_data(:),flow_data(:),[],@mean)];

Community Treasure Hunt

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

Start Hunting!

Translated by