Average of column for values of other columns

1 Ansicht (letzte 30 Tage)
Rogier Busscher
Rogier Busscher am 22 Nov. 2017
Bearbeitet: KL am 22 Nov. 2017
I have a matrix containing a:locations, b:dayoftheweek, c:hour, d:quarter e: intensities
I need average intensities per each quarter, for each unique location, day and hour.
My data
location day hour quarter intensity
240 1 0 1 18
240 1 0 1 26
240 6 7 3 23
240 28 22 1 9
242 5 15 2 35
240 1 0 1 14
etc
So i would like to make a script that would find mean(18,26,14)=19,33
Is there a more efficient way to do this compared to a loop?

Akzeptierte Antwort

KL
KL am 22 Nov. 2017
Bearbeitet: KL am 22 Nov. 2017
data = [240 1 0 1 18
240 1 0 1 26
240 6 7 3 23
240 28 22 1 9
242 5 15 2 35
240 1 0 1 14];
res = accumarray(data(data(:,1)==240,4),data(data(:,1)==240,5),[],@mean)
Robust way to deal with such data is to use tables or timetables

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by