Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Mar 1, 2012, 12:45 PM   #1
dukebound85
macrumors P6
 
dukebound85's Avatar
 
Join Date: Jul 2005
Location: 5045 feet above seal level
Code Question

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
dukebound85 is offline   0 Reply With Quote
Old Mar 1, 2012, 12:49 PM   #2
balamw
Moderator
 
balamw's Avatar
 
Join Date: Aug 2005
Location: New England, USA
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
__________________
MBA (13" 1.7 GHz 128GB), UMBP (15" SD 2.8 GHz), UMB (13" 2.4 GHz), iMac (17" Yonah), 32GB iPad 3 WiFi+LTE, 64 GB iPad WiFi, 32 GB iPhone 5, Airport Extreme
balamw is offline   0 Reply With Quote
Old Mar 1, 2012, 01:41 PM   #3
dukebound85
Thread Starter
macrumors P6
 
dukebound85's Avatar
 
Join Date: Jul 2005
Location: 5045 feet above seal level
Quote:
Originally Posted by balamw View Post
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
dukebound85 is offline   0 Reply With Quote
Old Mar 1, 2012, 01:47 PM   #4
balamw
Moderator
 
balamw's Avatar
 
Join Date: Aug 2005
Location: New England, USA
Start with:

Quote:
imonth = 100*year+month;
That gives you a single variable to loop over.

B
__________________
MBA (13" 1.7 GHz 128GB), UMBP (15" SD 2.8 GHz), UMB (13" 2.4 GHz), iMac (17" Yonah), 32GB iPad 3 WiFi+LTE, 64 GB iPad WiFi, 32 GB iPhone 5, Airport Extreme
balamw is offline   0 Reply With Quote
Old Mar 1, 2012, 04:00 PM   #5
dukebound85
Thread Starter
macrumors P6
 
dukebound85's Avatar
 
Join Date: Jul 2005
Location: 5045 feet above seal level
Quote:
Originally Posted by balamw View Post
Start with:



That gives you a single variable to loop over.

B
Thanks for the suggestion
dukebound85 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Photoshop Activation Codes Question Afro1989 Mac Basics and Help 18 Feb 13, 2006 01:58 AM
iTunes free music code question mac41099 Mac Applications and Mac App Store 2 Jan 18, 2006 01:09 PM
JavaScript Randomizer Code Questions Macs R Us Web Design and Development (archive) 0 Apr 20, 2005 07:09 PM
cocoa code question (help!) FredAkbar Mac Applications and Mac App Store 21 Jun 11, 2004 07:51 PM
Mac DVD Player & Region Codes Question... blauvs Mac Applications and Mac App Store 1 Jan 4, 2004 07:41 PM


All times are GMT -5. The time now is 06:24 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC