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:
matrix_re-order_please_help

Subject: matrix_re-order_please_help

From: aiden

Date: 13 Oct, 2010 00:49:03

Message: 1 of 6



Hi,

I have a matrix that I need to shuffle elements. the matrix is an '(N-1) x N' matrix.

So the matrix is as follows (I'm doing a 3x4 sample):

[ a1 b1 c1 d1
  c2 a2 b2 e1
  d2 e2 a3 b3]

I must reform the matrix in the following form:

a1 b1
a2 b2
a3 b3
c2 c1
d2 d1
e2 e1


My input matrix size can increase , so for a 4x5 sample would be as follows:

[ a1 b1 c1 d1 e1
  c2 a2 b2 f1 g1
  d2 f2 a3 b3 h1
  e2 g2 h2 a4 b4]

The reformed matrix should be in the form:

a1 b1
a2 b2
a3 b3
a4 b4
c2 c1
d2 d1
e2 e1
f2 f1
g2 g1
h2 h1

I currently have to reformat the following 4x5 matrix:


[ 17 24 1 8 15
      23 5 7 14 16
       4 6 13 20 22
      10 12 19 21 3]

to the form:

17 24
5 7
13 20
21 3
23 1
4 8
10 15
6 14
12 16
19 22

I am very confused about it. Need some help please friends.

aiden

Subject: matrix_re-order_please_help

From: Jan Simon

Date: 13 Oct, 2010 12:26:03

Message: 2 of 6

Dear aiden,

> [ a1 b1 c1 d1
> c2 a2 b2 e1
> d2 e2 a3 b3]
>
> I must reform the matrix in the following form:
> a1 b1
> a2 b2
> a3 b3
> c2 c1
> d2 d1
> e2 e1

There is an infinite number of schemes which convert the 1st to te 2nd matrix. Even the second example with a 4x5 matrix does not clarify how the procedure is exactly defined.
Therefore I can confirm, that this problem is confusing.

Perhaps you want to tell us, how the mixing procedure is defined for an arbitrary matrix. And most likely such an exact and clear definition can be implemented very easy.

Kind regards, Jan

Subject: matrix_re-order_please_help

From: Oleg Komarov

Date: 13 Oct, 2010 15:00:06

Message: 3 of 6

> There is an infinite number of schemes which convert the 1st to te 2nd matrix. Even the second example with a 4x5 matrix does not clarify how the procedure is exactly defined.
> Therefore I can confirm, that this problem is confusing.
>
> Perhaps you want to tell us, how the mixing procedure is defined for an arbitrary matrix. And most likely such an exact and clear definition can be implemented very easy.
>
> Kind regards, Jan

I agree with Jan.

Oleg

Subject: matrix_re-order_please_help

From: Roger Stafford

Date: 13 Oct, 2010 19:29:04

Message: 4 of 6

"aiden " <aidenjobe@gmail.com> wrote in message <i92vlv$fq2$1@fred.mathworks.com>...
> ......
> I have a matrix that I need to shuffle elements. the matrix is an '(N-1) x N' matrix.
> ......
- - - - - - - - - -
  Assuming A is an N-1 by N array, the following is what I believe to be the generalization of the "shuffle" of A for any N over to an array B which you have described. Is this correct?

p = tril(repmat((1:N-1).',1,N-1));
p = p(p~=0);
q = tril(repmat((1:N-1),N-1,1),-1);
q = [p(1:N-1);q(q~=0)];
r = [p;q]+(N-1)*[q-1;p];
B = reshape(A(r),[],2);

Roger Stafford

Subject: matrix_re-order_please_help

From: Bruno Luong

Date: 13 Oct, 2010 21:05:04

Message: 5 of 6

B=A.';
[diag(A,0) diag(A,1);
 A(tril(true(size(A)),-1)) B(tril(true(size(B)),-2))]

% Bruno

Subject: matrix_re-order_please_help

From: Jan Simon

Date: 13 Oct, 2010 21:50:06

Message: 6 of 6

Bruno, Roger,

you are bold. If the OP confirms your ideas, which are surely based on the assumption of a minimal entropy of the algorithm, I'll be convinced that own magic cristal balls.

I have the sequence [1,2,3,4,5,6,7,8,9,10] and want to get a general aproach for getting [8,5,4,9,1,7,6,10,3,2].

Kind regards, Jan

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