Re: Hours Mean Values for meteorological date



Frank Cabrera wrote:
Hi, I have a file.xls (Excel) with the following information arranged by column:

Date (for example 11-23-06). This column goes from 01-01-06 to 12-31-06
Hour (for example 21:23). This column goes from 00:00 to 23:59
Temperature
Wind velocity
Wind direction
Radiation

So, my first question is: How do I import these variables to Matlab? Then, I need to do hours mean of each these variables. Nevertheless, I don?t have the same quantities of dates in all hours. For example, I can to have 30 dates in an hour, but 56 dates in another hour (the quantities of dates is not constant). So, my second question will be: How do I do an algorithm to get the hours mean values of these variables during a year complete? Thank you very much.

Frank, I assume what you mean is that you want to compute the mean of those last four variables, by hour, across all dates. If you have access to the Statistics Toolbox, you can use a dataset array for this. Use something like

ds = dataset('XLSFile','yourfile.xls')

to read the data in. Depending on what's in that file, you may want to set 'ReadVarNames' to false in that call, and provide your own var names. The dates and times will be read in as strings, the others as doubles (presumably). You'll want to convert those time strings into hour numbers, perhaps as

dvec = datevec(ds.Time,'HH:MM'); ds.Hour = dvec(:,4);

and then compute the hourly means as

means = grpstats(ds,'Hour',@mean,'DataVars',{'Temp' 'Veloc' 'Dir' 'Rad'})

which creates a new dataset array with the grouped means, by hour. (I may not have the syntax exactly right; typing from memory.)

Hope this helps.

- Peter Perkins
The MathWorks, Inc.
.