Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
ismember question

Subject: ismember question

From: Liqing

Date: 25 Mar, 2010 18:38:04

Message: 1 of 4

I have two n by 5 matrixes, like below:

% The 5 columns are SiteNum, Year, Month, Day, Value, respectively.
M = [ 31007 1955 2 15 7.8;
         31007 1955 2 16 7.1;
         31007 1955 3 7 8.8;
         31025 1956 1 2 7.6;
         31025 1956 1 5 9.5
         ...];

N = [31007 1955 2 15 256;
       31007 1955 3 7 467;
       31025 1956 1 2 105;
       32048 1957 5 9 67
         ...];

I will need to generate a third 6-column matrix with SiteNum, Year, Month, Day, Value1, Value2. Value1 and Value2 are from the M(:,5) and N(:,5), respectively. They have to share the same SiteNum, Year, Month, Day, so that I can do the further calculation.

Anyone can help me? Thank you in advance.

Subject: ismember question

From: Roger Stafford

Date: 25 Mar, 2010 19:10:11

Message: 2 of 4

"Liqing" <liqingj@gmail.com> wrote in message <hogaic$4go$1@fred.mathworks.com>...
> I have two n by 5 matrixes, like below:
>
> % The 5 columns are SiteNum, Year, Month, Day, Value, respectively.
> M = [ 31007 1955 2 15 7.8;
> 31007 1955 2 16 7.1;
> 31007 1955 3 7 8.8;
> 31025 1956 1 2 7.6;
> 31025 1956 1 5 9.5
> ...];
>
> N = [31007 1955 2 15 256;
> 31007 1955 3 7 467;
> 31025 1956 1 2 105;
> 32048 1957 5 9 67
> ...];
>
> I will need to generate a third 6-column matrix with SiteNum, Year, Month, Day, Value1, Value2. Value1 and Value2 are from the M(:,5) and N(:,5), respectively. They have to share the same SiteNum, Year, Month, Day, so that I can do the further calculation.
>
> Anyone can help me? Thank you in advance

  Apply the intersect function to M(:,1:4) and N(:,1:4) using the 'rows' option, and use the resulting index vector to get your desired result.

Roger Stafford
.

Subject: ismember question

From: Roger Stafford

Date: 25 Mar, 2010 19:16:04

Message: 3 of 4

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <hogcei$75k$1@fred.mathworks.com>...
> Apply the intersect function to M(:,1:4) and N(:,1:4) using the 'rows' option, and use the resulting index vector to get your desired result.
> Roger Stafford

  I should have said 'vectors', plural. You get two index vectors returned and you need them both.

Roger Stafford

Subject: ismember question

From: Liqing

Date: 25 Mar, 2010 19:18:05

Message: 4 of 4

That absolutely solved my problem!!!

Thank you so much, Roger.

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <hogcei$75k$1@fred.mathworks.com>...
> "Liqing" <liqingj@gmail.com> wrote in message <hogaic$4go$1@fred.mathworks.com>...
> > I have two n by 5 matrixes, like below:
> >
> > % The 5 columns are SiteNum, Year, Month, Day, Value, respectively.
> > M = [ 31007 1955 2 15 7.8;
> > 31007 1955 2 16 7.1;
> > 31007 1955 3 7 8.8;
> > 31025 1956 1 2 7.6;
> > 31025 1956 1 5 9.5
> > ...];
> >
> > N = [31007 1955 2 15 256;
> > 31007 1955 3 7 467;
> > 31025 1956 1 2 105;
> > 32048 1957 5 9 67
> > ...];
> >
> > I will need to generate a third 6-column matrix with SiteNum, Year, Month, Day, Value1, Value2. Value1 and Value2 are from the M(:,5) and N(:,5), respectively. They have to share the same SiteNum, Year, Month, Day, so that I can do the further calculation.
> >
> > Anyone can help me? Thank you in advance
>
> Apply the intersect function to M(:,1:4) and N(:,1:4) using the 'rows' option, and use the resulting index vector to get your desired result.
>
> Roger Stafford
> .

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us