Reputation: 79
I have a series data of daily rainfall from Jan-01-1976 up to Dec-31-2001 for both predicted and observed. And what i want to plot them into a graph of mean monthly from Jan-Feb...Dec. Can you tell me how to do it in Excel or Matlab ? Thank you very much !
Daily data
And i want it to be like this:
Upvotes: 0
Views: 3028
Reputation: 2826
First you will need to find which month each date falls upon. Judging by your linked data, you can do something simple but (i think) slow:
for i = 1:last_index
% use automatic date overflow of datevec() func
ldate = datevec(datenum(1976, 1, i))
month = ldate(2);
From that point you can assign observed and predicted data to months by associating each month with its respective index, i.e. January = 1, February = 2 etc.
After that, you can plot vertical bars for each month with the bar()
function.
Edit: ok, here's some more code. I assume your data is in the form predicted observed
, and resides in a vector called rainData
.
% create matrix for per-month data
monthlyData = zeros(12, 2);
% create matrix for month occurences
months = zeros(12, 1);
for i = 1:length(rainData)
% use automatic date overflow of datevec() func
ldate = datevec(datenum(1976, 1, i))
month = ldate(2);
% update month occurences
months(month) = months(month) + 1;
% update observed sum
monthlyData(month, :) = monthData(month, :) + rainData(i, :);
end
% extract means for each month
% dividing the sum of rain values for each month with the month's occurences
for i = 1:12
monthlyData(i, :) = monthlyData(i, :) / months(i);
end
At that point monthlyData is 12x2 array where each row corresponds to a month and has the form of [predictedValue observedValue]
. Use bar(monthlyData)
to plot a histogram-like figure.
Also, check out the Matrices and Arrays Tutorial if you have trouble understanding the indexing above.
Upvotes: 1