From: us on 26 May 2010 13:39 "Kyla Bishop" <kbishop(a)uvic.ca> wrote in message <htjk99$1lh$1(a)fred.mathworks.com>... > Hi, > I am new-ish to Matlab, so, bear with me. I have an array with 6 rows and about 140 000 columns of wind data. The first 4 rows are just strings that tell me the year, month, date and hour and the final two rows are my actual data. In this array I've got 16 years worth of hourly wind direction and speed data from a particular wind station. What I want to do is analyze the data by month, day and year to look for cycles (in particular annual and diurnal). > To access the ranges of data that I want I wrote a simple for loop > for a=1:length(d); where length(d) just assigns the # of days in the month > aa=find((output(1,:)==1994)&(output(2,:)==1)); this would be for Jan, 1994 > end > > then, to get, say, the wind direction for that range in the first and second columns: > aaa=ouput(5,aa); > I can take the mean of aaa easily and accurately by 'mean(aaa)' and it works well. > The problem is that some of my data is incomplete and there are multiple NaNs in my array. When I try to take the mean after removing the NaNs > mean(find(~isnan(aaa))) > what I end up with is no longer the mean of the data but the mean of the indices values. In other words, for Jan 1994 there were 744 data points and the mean I got after taking out the NaNs was somewhere around 360 when the actual wind direction mean is closer to 35. > > I would really appreciate some help with this! > thanks a hint: - if(f) you own the stats tbx help nanmean; % <- and siblings... - otherwise one of the solutions v=[1,1,1,nan,1,1]; r=mean(v(~isnan(v))) % <- logcial indexing and NOT FIND for obvious reasons.. % r = 1 us
From: TideMan on 26 May 2010 16:27 On May 27, 5:03 am, "Kyla Bishop" <kbis...(a)uvic.ca> wrote: > Hi, > I am new-ish to Matlab, so, bear with me. I have an array with 6 rows and about 140 000 columns of wind data. The first 4 rows are just strings that tell me the year, month, date and hour and the final two rows are my actual data. In this array I've got 16 years worth of hourly wind direction and speed data from a particular wind station. What I want to do is analyze the data by month, day and year to look for cycles (in particular annual and diurnal). > To access the ranges of data that I want I wrote a simple for loop > for a=1:length(d); where length(d) just assigns the # of days in the month > aa=find((output(1,:)==1994)&(output(2,:)==1)); this would be for Jan, 1994 > end > > then, to get, say, the wind direction for that range in the first and second columns: > aaa=ouput(5,aa); > I can take the mean of aaa easily and accurately by 'mean(aaa)' and it works well. > The problem is that some of my data is incomplete and there are multiple NaNs in my array. When I try to take the mean after removing the NaNs > mean(find(~isnan(aaa))) > what I end up with is no longer the mean of the data but the mean of the indices values. In other words, for Jan 1994 there were 744 data points and the mean I got after taking out the NaNs was somewhere around 360 when the actual wind direction mean is closer to 35. > > I would really appreciate some help with this! > thanks You need to think about this a bit more............. To find the mean direction, you cannot just take the mean of the directions. Why? Well, consider this: Let's say we have a North wind blowing for a few hours (direction zero), then it shifts slightly to the NNW (337.5 deg), then back to N again (zero degrees). Now, when you take the mean of those numbers, the result will be between 0 and 337.5 deg, like 180 deg (S wind!!) when it should be between 337.5 and zero deg (say, 355 deg). To get the mean speed and direction, you need to convert wind speed and direction to complex numbers (North and East wind components), calculate the mean, then transform that mean back to speed and direction (using abs and angle).
|
Pages: 1 Prev: state space form of discrete transfer function Next: vectorisation of 3D Matrix operation |