dpb <email@example.com> wrote in message <firstname.lastname@example.org>... > On 7/26/2013 12:13 PM, Jonathan wrote: > ... > > > I am trying to fill a matrix (CompletDat: 40020*7) containing mostly > > NaNs, with data from a second matrix (RealDat: 36446*7). > > The master file (CompletDat) contains discrete dates in the first > > column, which are repeated every 15 rows. A unique id is located in the > > second column, which is repeated for 15 rows, and then increments to the > > next value and so on. The rest of the columns are filled with NaNs. > > The second matrix has the same format except there are dates that are > > missing. Hence, the overall goal is to populate the CompletDat matrix > > with data from the other matrix, placing them in their correct row based > > on the same date and unique id. > > ... > > > For now I have been testing it on a small matrix (CompletDat: 30*7) and > > RealDat(26*7), the latter having four missing rows. I have played around > > with variations of this code but I can't seem to get it to work. Any > > help is greatly appreciated. > > A) What format are the dates? If you're comparing floats, have to be > careful of "off by one bit" differences if the two files' dates weren't > created identically. > > B) Should be able to create logical indexing arrays w/ ismember(), > intersect() and friends that would serve to find the various > combinations desired/needed. Seems like first step would be to find the > missing values that are need, then retrieve the matching data from the > second array. > > But, if these dates are known by there only being a few missing rather > than a complete group for any given ID it seems easiest way to fill in > would be to simply do that from the surrounding values. interp1() w/ > 'nearest' would likely be of help there. > > A short example showing the problem and desired solution would likely > help...probably only needs a couple lines of a couple combinations to be > sufficient. > > -- > The dates are identical. Hadn't thought about ismember. I just tried it and its correctly identifying the areas where dates are missing. The next step is how to retrieve the matching data from the second array, which is the area I have been struggling with. Using interp etc is not an option.
CompletDat =[15*4] 1997.66805 2583 NaN NaN 1998.24915 2583 NaN NaN 2002.66805 2583 NaN NaN 2007.741973 2583 NaN NaN 2007.966482 2583 NaN NaN 2008.254626 2583 NaN NaN 2008.755663 2583 NaN NaN 2009.246412 2583 NaN NaN 2009.725546 2583 NaN NaN 2009.952792 2583 NaN NaN 2010.079399 2583 NaN NaN 2010.766615 2583 NaN NaN 2011.164275 2583 NaN NaN 2012.79947 2583 NaN NaN 2012.950055 2583 NaN NaN