Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

dukebound85

macrumors Core
Original poster
Jul 17, 2005
19,131
4,110
5045 feet above sea level
I am trying to do the following.

I have a 7670 array of data
I also have complimentary arrays that are 7670 in length that are the day, month, and year

For instance
data = [1,7670] = [.3,.45,.56,.67, etc].....to index 7670 with just data values
day = [1,2,3,4,5...31,1,2,3,4,....28,1,2,3,4....30] repeating for 7670 indexes. These are the value of the days in the particular month
month = [1,1,1,1,1,(31 times), 2,2,2,2,2,2,(28 times), etc] for 7670 indexes
year = [1980,1980,1980, (365 times), 1981,1981, (365 times),] etc for 7670 indexes

My question is how can I take this daily data and average it for each month...so my 7670 array is about 650 in length

Here is what I have right now. This is matlab
Code:
count = 1;
for i=1:7670
    if i < 7670
        while day(i+1)>day(i)
            k = 1;
            index(count,k) = day(i);
            k = k+1;            
        end
            
            u300_PC1_monthly_avg(count) = mean(u300_PC1(index(count,1):size(index,2)));
            count = count+1;
            i = i+1;
    end
end
 

balamw

Moderator emeritus
Aug 16, 2005
19,366
979
New England
I'd create a new data array and loop over year then month (nested loops).

Every time you get a change in year or month increment the index of the new structure and start a new average.

Does that help?

EDIT: (Sorry, I missed that it was MATLAB).

You could easily use a sparse matrix instead of the indexed one. Just use Year*100+Month as the index for the sparse matrix. This gives you an easy way to look up the data too.

B
 

dukebound85

macrumors Core
Original poster
Jul 17, 2005
19,131
4,110
5045 feet above sea level
I'd create a new data array and loop over year then month (nested loops).

Every time you get a change in year or month increment the index of the new structure and start a new average.

Does that help?

EDIT: (Sorry, I missed that it was MATLAB).

You could easily use a sparse matrix instead of the indexed one. Just use Year*100+Month as the index for the sparse matrix. This gives you an easy way to look up the data too.

B


Sort of. I feel like I could avoid loops but just having a hard time implemeting the logic in my code
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.