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: 116
Registered: 12/7/04
Re: comparing and filling matrices
Posted: Jul 26, 2013 2:52 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

dpb <none@non.net> wrote in message <ksufrj$5ll$1@speranza.aioe.org>...
> On 7/26/2013 1:01 PM, Jonathan wrote:
> > dpb <none@non.net> wrote in message <ksubob$pnu$1@speranza.aioe.org>...
> >> On 7/26/2013 12:13 PM, Jonathan wrote:
> >> ...
> >>

> >> > I am trying to fill a matrix (CompletDat:
> >> > with data from a second matrix (RealDat:
> >> > (CompletDat) contains discrete dates in the first
> >> > column, which are repeated every 15 rows. A unique id is located in the
> >> > second column, ... repeated for 15 rows, and then increments to the
> >> > next value and so on. ...
> >> > 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.
> >>

> ...
>

> >> 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 it's 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.
> >
> > Here's a sample of the data...
> >
> > RealDat = [13*4]
> > 1997.66805 2583 21 0 84.85
> > 1998.24915 2583 21 0 80.02
> > 2002.66805 2583 21 0 90.03
> > 2007.741973 2583 21 0 85.25
> > 2008.254626 2583 21 0 79.25
> > 2008.755663 2583 21 0 83.24

> ...
> > C =[
> 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
> ...
>
> Well, first have to augment the C array to full rank of R or would have
> to switch to cell array to handle jagged array.
>
> C=[C C(:,3)];
>
> Then, simply use the ismember() logical array...
>

> >> C(ismember(C(:,1:2),R(:,1:2),'rows'),3:end)=R(:,3:end)
> C =
> 1.0e+03 *
> 1.9977 2.5830 0.0210 0 0.0848
> 1.9982 2.5830 0.0210 0 0.0800
> 2.0027 2.5830 0.0210 0 0.0900
> 2.0077 2.5830 0.0210 0 0.0853
> 2.0080 2.5830 NaN NaN NaN
> 2.0083 2.5830 0.0210 0 0.0793
> 2.0088 2.5830 0.0210 0 0.0832
> 2.0092 2.5830 0.0210 0 0.0798
> 2.0097 2.5830 0.0210 0 0.0967
> 2.0100 2.5830 NaN NaN NaN
> 2.0101 2.5830 0.0210 0 0.0764
> 2.0108 2.5830 0.0210 0 0.0972
> 2.0112 2.5830 0.0210 0 0.0972
> 2.0128 2.5830 0.0210 0 0.1018
> 2.0130 2.5830 0.0210 0 0.0922

> >>
>
> --
>

Thank you, this worked perfectly. Makes a mockery of my loop attempt.

Cheers
Jon



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

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.