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
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
 

Ron C

macrumors member
Jul 18, 2008
61
0
Chicago-area
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."
 

chown33

Moderator
Staff member
Aug 9, 2009
10,740
8,416
A sea of green
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?
 

subsonix

macrumors 68040
Feb 2, 2008
3,551
79
What language are you using? There are date functions available to do what you want without storing every date in an array.
 

dukebound85

macrumors Core
Original poster
Jul 17, 2005
19,131
4,110
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:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.