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:
join row from 2 matrix in a specific order

Subject: join row from 2 matrix in a specific order

From: Andrea

Date: 4 Oct, 2012 17:06:08

Message: 1 of 5

Dear all

I have 2 24by6 matrices (A and B) and I need to create a new matrix (C - which will be a 24by12) based on these 2.
Specifically, considering the first row of both A and B I need that the first row of C built according to the order expressed by this matrix D:

D_1=
1 2 4 5 2 3 5 6 2 3 5 1 3 4 6 6
1 1 1 1 2 2 2 2 1 1 1 2 2 2 2 1
1 1 2 2 3 3 4 4 1 1 2 2 3 3 4 4

In D_1:
- the first row represent the items in the 1st row of A or B
- 1 in the second row of D means that the item in the 1st row of D is related to matrix A, whereas 2 is related to matrix B
- the third row is used to randomised D -> the first two columns have 1 because they are group1, the 3rd and 4th columns are group 2 and so on until group 4 (7th and 8th columns) then it starts again from 1 to 4. In the example above the order is straight from 1 to 4 but in the final script it will be randomise, but each group is always the same - i.e. composed by the same 1st and 2nd rows. So another example of D could be:

e.g.
D_2=
4 5 5 6 2 3 1 2 2 3 3 4 6 6 5 1
1 1 2 2 1 1 2 2 1 1 2 2 2 1 1 2
2 2 4 4 3 3 1 1 1 1 3 3 4 4 2 2

in this example the group order of D according to its 3rd row is 2-4-3-1 for the first part and 1-3-4-2 for the second part

Having defined D, which will change for each of the 24 rows of C, the first row of C is based on the order stated in the first and the second row of D_1.
For example, based on D_1, the first row of C will be:
 
C(1,1) = A(1,1)
C(1,2) = A(1,2)
C(1,3) = A(1,4)
C(1,4) = A(1,5)
C(1,5) = B(1,2)
C(1,6) = B(1,3)
...
C(1,11) = B(1,6)
C(1,12) = A(1,6)

then the second row of C will be based on D_2 and so on until the 24th row.

Any idea?

thank you very much
Andrea

Subject: join row from 2 matrix in a specific order

From: dpb

Date: 4 Oct, 2012 17:25:54

Message: 2 of 5

On 10/4/2012 12:06 PM, Andrea wrote:
> Dear all
>
> I have 2 24by6 matrices (A and B) and I need to create a new matrix (C -
> which will be a 24by12) based on these 2.
> Specifically, considering the first row of both A and B I need that the
> first row of C built according to the order expressed by this matrix D:
...

> Any idea?
...

See my response just earlier this AM to Hato re: How to reindexing an
array...a generalization thereof should suit what is a very similar problem.

--

Subject: join row from 2 matrix in a specific order

From: Andrea

Date: 4 Oct, 2012 17:37:10

Message: 3 of 5

dpb <none@non.net> wrote in message <k4kgqu$da3$1@speranza.aioe.org>...
> On 10/4/2012 12:06 PM, Andrea wrote:
> > Dear all
> >
> > I have 2 24by6 matrices (A and B) and I need to create a new matrix (C -
> > which will be a 24by12) based on these 2.
> > Specifically, considering the first row of both A and B I need that the
> > first row of C built according to the order expressed by this matrix D:
> ...
>
> > Any idea?
> ...
>
> See my response just earlier this AM to Hato re: How to reindexing an
> array...a generalization thereof should suit what is a very similar problem.
>
> --

Thanks dpb, I know how to index a vector, but I was wondering if there is something more elegant that allow me to randomise and order each row in the same loop.

Thank you very much

Andrea

Subject: join row from 2 matrix in a specific order

From: dpb

Date: 4 Oct, 2012 18:00:38

Message: 4 of 5

On 10/4/2012 12:37 PM, Andrea wrote:
...

> Thanks dpb, I know how to index a vector, but I was wondering if there
> is something more elegant that allow me to randomise and order each row
> in the same loop.
...

doc randperm % maybe?

Not sure what the question really is here...or why you need a loop,
necessarily.

I didn't try to read thru the whole thing earlier as seemed awfully
longwinded... :)

If there's still a ? after this, how 'bout a shorter sample
problem/example? It doesn't take but a small subset rather than the
fullblown size to demonstrate...

--

Subject: join row from 2 matrix in a specific order

From: dpb

Date: 4 Oct, 2012 20:18:39

Message: 5 of 5

On 10/4/2012 12:06 PM, Andrea wrote:
...

> I have 2 24by6 matrices (A and B) and I need to create a new matrix (C -
> which will be a 24by12) based on these 2.
> Specifically, considering the first row of both A and B I need that the
> first row of C built according to the order expressed by this matrix D:
> D_1=
> 1 2 4 5 2 3 5 6 2 3 5 1 3 4 6 6 1 1 1 1 2 2 2 2 1 1 1 2 2 2 2 1 1 1 2 2
> 3 3 4 4 1 1 2 2 3 3 4 4
> In D_1:
> - the first row represent the items in the 1st row of A or B
> - 1 in the second row of D means that the item in the 1st row of D is
> related to matrix A, whereas 2 is related to matrix B
> - the third row is used to randomise D...

I have to confess I can't make heads nor tails of this...first off,
there aren't three rows perhaps thanks to the newsreader wrapping lines
but even if so there are by count of length by pasting into Matlab only
48 values which isn't enough for a third row of 24. If I reshape to 6
columns I have eight rows and don't see how that correlates w/ rows
1,2,3 function as outlined...

I'll stop at that point w/o even beginning on trying to decipher the
coding from the description... :(

As previously suggested, cut the size down to something that fits on a
screen in the command window and try again...

--

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