Search All of the Math Forum:

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

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

 Messages: [ Previous | Next ]
 Jonathan Allan Posts: 123 Registered: 12/7/04
comparing and filling matrices
Posted: Jul 26, 2013 1:13 PM

G?day,

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);
end
end
end

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.
Thanks
Jon

Date Subject Author
7/26/13 Jonathan Allan
7/26/13 dpb
7/26/13 Jonathan Allan
7/26/13 dpb
7/26/13 Jonathan Allan
7/26/13 dpb