- 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?
Info
Questa domanda è chiusa. Riaprila per modificarla o per rispondere.
How to aggregate data and calculate its standard deviation
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
per isakson
il 8 Lug 2013
Modificato: per isakson
il 8 Lug 2013
Firstly, a couple of questions:
Risposte (1)
dpb
il 8 Lug 2013
Modificato: dpb
il 8 Lug 2013
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... :)
0 Commenti
Questa domanda è chiusa.
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!