How to consolidate rows with same value, while adding their cells?
Mostrar comentarios más antiguos
I have NOAA climate data reported every 15 minutes and need to consolidate it into daily info. I want to add cells at the end of a row together that have the same date, and make a new matrix with the 'summed' and consolidated info. Here is a rough example of what I want to do:
FROM:
[date, precip
2/1, 4
2/1, 5
2/1, 6
2/2, 2
2/2, 3
2/2, 1
2/2, 4]
TO:
[date, precip
2/1, 15
2/2, 10]
Respuesta aceptada
Más respuestas (1)
Azzi Abdelmalek
el 12 de Nov. de 2013
Editada: Azzi Abdelmalek
el 12 de Nov. de 2013
s = { '2/1', 4; '2/1', 5; '2/1', 6; '2/2', 2; '2/2', 3; '2/2', 1; '2/2',4}
[a,b,c]=unique(s(:,1),'stable')
out=[a num2cell(accumarray(c,cell2mat(s(:,2))))]
Categorías
Más información sobre Climate Science and Analysis en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!