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 Jun 10, 2012, 12:46 PM   #1
dukebound85
macrumors P6
 
dukebound85's Avatar
 
Join Date: Jul 2005
Location: 5045 feet above sea level
Create a Calender matrix

Hi all, I have a quick question. I have gridded data I am trying to manipulate and for the sake of existing code I have written (that had this type of index with the data embedded in the netcdf file) would like to create an auxillary matrix with the corresponding time

For instance, I have 12,xxx indexes that correspond to each day between Jan 1, 1979 to Dec 31, 2011

I would like to create a 4x12,xxx array that is of the following behavior

(Record, Month, Day, Year) where each one is 12,xxx in length

Record is the raw index value (1-12,xxx)
Month is the coressponding month of the index value (ie 31 consecutive 1's for Janurary, 28 consecutive 2s for Feb, etc and repeats)
Day is the corresponding day (1-28(31)) for the index
Year is the corresponding year (365 consecutive 1979, then 365 1980s, etc)

Is there an easy way to make this type of array? I would need to take into accoun the leap years and what not

Thanks for any tips
dukebound85 is offline   0 Reply With Quote
Old Jun 10, 2012, 01:09 PM   #2
Ron C
macrumors member
 
Join Date: Jul 2008
Location: Chicago-area
Quote:
Originally Posted by dukebound85 View Post
Hi all, I have a quick question. I have gridded data I am trying to manipulate and for the sake of existing code I have written (that had this type of index with the data embedded in the netcdf file) would like to create an auxillary matrix with the corresponding time

For instance, I have 12,xxx indexes that correspond to each day between Jan 1, 1979 to Dec 31, 2011

I would like to create a 4x12,xxx array that is of the following behavior

(Record, Month, Day, Year) where each one is 12,xxx in length

Record is the raw index value (1-12,xxx)
Month is the coressponding month of the index value (ie 31 consecutive 1's for Janurary, 28 consecutive 2s for Feb, etc and repeats)
Day is the corresponding day (1-28(31)) for the index
Year is the corresponding year (365 consecutive 1979, then 365 1980s, etc)

Is there an easy way to make this type of array? I would need to take into accoun the leap years and what not

Thanks for any tips
I wouldn't store that information, rather I'd compute it for a given index.

I'd start by figuring out how to convert the index into the appropriate NSTimeInterval value, then I'd use the NSDate and NSDateComponents classes to help me figure out the information I'm looking for. Read the documentation for more information on these classes, particularly the "Date and Time Programming Guide" - it gives you the answer in a section titled "Converting between Dates and Date Components."
__________________
MBP, MB, mini, PB G4(x2), eMac, ...
Ron C is offline   0 Reply With Quote
Old Jun 10, 2012, 01:10 PM   #3
chown33
macrumors 603
 
Join Date: Aug 2009
1. Which language?

2. The intended meaning of "12,xxx" is unclear (though it might be clearer if we knew which language). Do you mean "approximately 12 thousand (~12,000, ~12k, ~12e3)" since the number of days in your date range is approximately 12 thousand (12,053)? Or do you mean "twelve" and the ",xxx" has some additional meaning? Or do you mean something else?
chown33 is offline   0 Reply With Quote
Old Jun 10, 2012, 01:12 PM   #4
subsonix
macrumors 68030
 
Join Date: Feb 2008
What language are you using? There are date functions available to do what you want without storing every date in an array.
subsonix is offline   0 Reply With Quote
Old Jun 10, 2012, 01:14 PM   #5
dukebound85
Thread Starter
macrumors P6
 
dukebound85's Avatar
 
Join Date: Jul 2005
Location: 5045 feet above sea level
I am creating the array in matlab. The 12,xxx is more explicitly 12,053 values

here is how I initially approached the problem.

Code:
%% Calender maker

record = [1:1:12053];

y79 = [1:1:365];
y80 = [1:1:366];
y81 = [1:1:365];
y82 = [1:1:365];
y83 = [1:1:365];
y84 = [1:1:366];
y85 = [1:1:365];
y86 = [1:1:365];
y87 = [1:1:365];
y88 = [1:1:366];
y89 = [1:1:365];
y90 = [1:1:365];
y91 = [1:1:365];
y92 = [1:1:366];
y93 = [1:1:365];
y94 = [1:1:365];
y95 = [1:1:365];
y96 = [1:1:366];
y97 = [1:1:365];
y98 = [1:1:365];
y99 = [1:1:365];
y00 = [1:1:366];
y01 = [1:1:365];
y02 = [1:1:365];
y03 = [1:1:365];
y04 = [1:1:366];
y05 = [1:1:365];
y06 = [1:1:365];
y07 = [1:1:365];
y08 = [1:1:366];
y09 = [1:1:365];
y10 = [1:1:365];
y11 = [1:1:365];

day = [y79,y80,y81,y82,y83,y84,y85,y86,y87,y88,y89,y90,y91,y92...
    y93,y94,y95,y96,y97,y98,y99,y00,y01,y02,y03,y04,y05,y06,...
    y07,y08,y09,y10,y11]';
I have netcdf files with length of the record dimension and am trying to manipulate it via data so hence my complimentary matrix I am attempting to recreate if that makes sense

Edit: Figured it out...even though my code to generate it is not the most elagant!

Last edited by dukebound85; Jun 10, 2012 at 02:24 PM.
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

Similar Threads
thread Thread Starter Forum Replies Last Post
I like the new Calender changes but..... marlman iOS 7 1 Mar 11, 2014 10:15 AM
iPhone: Jailbreak Matrix smorris79 Jailbreaks and iOS Hacks 2 Dec 20, 2013 06:33 AM
Calender and Mail changes? dannys1 OS X Mavericks (10.9) 1 Aug 25, 2013 04:06 PM
Calender invitations Drich290195 iOS 6 0 Nov 19, 2012 07:05 AM
Lost calender! Kelbelle iPhone Tips, Help and Troubleshooting 1 Jun 26, 2012 05:31 PM

Forum Jump

All times are GMT -5. The time now is 07:18 PM.

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

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