calculate the annual discharge over several years
Mostrar comentarios más antiguos
Hello,
I have a time series dataset that consists of daily discharge (Q) data from 1915-2006. My matrix: the first column is the year, the second is the month, the third is the day and the fourth column is the data of interest (Q). I need to calculate the mean annual discharge for each year and then arrange the data from the smallest Q to largest Q but knowing to which year that Q belongs.
- Year Month day Q
- 1915 10 1 2.13E+02
- 1915 10 2 2.89E+02
- 1915 10 3 8.10E+02
- ...
- ...
- 2006 12 31 2.20E+04
I am very new at Matlab and even though I found some similar examples online I can't figure this out. Any help will be really appreciated.
Thanks!
2 comentarios
Can you show sample for your data? Perhaps you can also look at:
doc mean
in your MATLAB command window and it will give you some idea
Jeremy
el 29 de Oct. de 2013
Also look at the 'sort" function, specifically when called with 2 outputs.
Respuesta aceptada
Más respuestas (1)
sixwwwwww
el 29 de Oct. de 2013
Dear Maria, here is the code for required functionality:
ID = fopen('filename.txt');
data = textscan(ID, '%f%f%f%f');
fclose(ID);
year = data{1};
interest = data{4};
count = 1;
i = 1915:2006;
avg = zeros(length(i), 2);
for i = 1915:2006
ind = find(ismember(year, i));
avg(count, 1) = i;
avg(count, 2) = sum(interest(ind)) / length(ind);
count = count + 1;
end
avg = sortrows(avg, 2);
disp(avg)
I hope it helps. Good luck!
1 comentario
Maria Mateus
el 29 de Oct. de 2013
Categorías
Más información sobre Data Type Identification 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!