Drexel dragonThe Math ForumDonate to the Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: comparing and filling matrices
Replies: 5   Last Post: Jul 26, 2013 3:01 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Jonathan Allan

Posts: 120
Registered: 12/7/04
comparing and filling matrices
Posted: Jul 26, 2013 1:13 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply


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.

My initial code is as follows:

for m=2583:2584; %unique transect id
for i=1:length(CompletDat(:,1))
[idx1] = find(RealDat(:,1)== CompletDat(i,1)); %compare dates
if and(m==RealDat(i,2),RealDat(:,1)== CompletDat(i,1))
CompletDat(idx1(i),2) = RealDat(idx1(i),2);
CompletDat(idx1(i),3) = RealDat(idx1(i),3);
CompletDat(idx1(i),4) = RealDat(idx1(i),4);
CompletDat(idx1(i),5) = RealDat(idx1(i),5);
CompletDat(idx1(i),6) = RealDat(idx1(i),6);
CompletDat(idx1(i),7) = RealDat(idx1(i),7);

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.

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum 1994-2015. All Rights Reserved.