Info

この質問は閉じられています。 編集または回答するには再度開いてください。

How to aggregate data and calculate its standard deviation

1 回表示 (過去 30 日間)
Abraham
Abraham 2013 年 6 月 20 日
Hi
I have two matrix with 1) day 2) travel time (sec). Where there are several observations of travel times per day. And date for more than two years.
day .......Traveltime
1 .............220
1 .............230
1 .............240
2 .............210
2 .............210
...etc
How can I aggregate the data_, so that I will have only one observation (average travel time) per day, and the standard deviation for each day.
So that the output, will be something like this:
day.......average_time.......Std_dev
1............230.............10
2............210.............0
I would appreciate if you can help me.
  2 件のコメント
per isakson
per isakson 2013 年 7 月 8 日
編集済み: per isakson 2013 年 7 月 8 日
Firstly, a couple of questions:
  • The input data is that a text file? Or double array? Or a cell array?
  • " are several observations of travel times per day" does that mean that the length of the lines/row varies?
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 7 月 17 日

回答 (1 件)

dpb
dpb 2013 年 7 月 8 日
編集済み: dpb 2013 年 7 月 8 日
I'll presume you have two vectors d and t; if so you can make a matrix as
MATl
>> m = [d t]
m =
1 220
1 230
1 240
2 210
2 210
>> [u,~,c] = unique(m(:,1)); % get the unique days, locations
>> [u,accumarray(c,m(:,2),[],@mean),accumarray(c,m(:,2),[],@std)]
ans =
1 230 10
2 210 0
>>
Or, of course, you can use the two vectors directly w/o the concatenations...
MATL
>> [u,~,c] = unique(d);
>> [u,accumarray(c,t,[],@mean),accumarray(c,t,[],@std)]
ans =
1 230 10
2 210 0
>>
Why didn't just use them first time is beyond me... :)

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by