splitting matrix to different row

I have the following matrix and I want to split it.
A=[0 2 4 ,5 0 4]
it should be like this:
[0 2]
[2 4]
[4 2]
[5 0]
[0 4]
[4 5]
Please write me, If you have answer. Thanks

4 comentarios

Azzi Abdelmalek
Azzi Abdelmalek el 26 de Mayo de 2016
Editada: Azzi Abdelmalek el 26 de Mayo de 2016
A=[0 2 4 ,5 0 4] is a row vector. And you didn't explain how to get the result
Joseph Cheng
Joseph Cheng el 26 de Mayo de 2016
also looking at the little pattern you have should [4 2] be [4 0] as it looks like the [4 5] as a wrap around pairing
Ali
Ali el 26 de Mayo de 2016
Editada: Ali el 26 de Mayo de 2016
Many thanks for the response.. I wrote it wrong.
I have a matrix with 260 row and 3 columns. I would like to produce a matrix with 780 row and 2 columns. for instance:
A=[0 2 4; 5 0 4]
I would like to have something like this:
[0 2]
[2 4]
[4 0]
[5 0]
[0 4]
[4 5]
I was sent the following via email. I think it is a clearer statement of the request:
# Elements
1 0 2
0 3 2
4 1 6
6 1 2
3 5 7
3 7 2
6 2 7
8 4 6
I would like to have this:
1 0
0 2
2 1
0 3
3 2
2 0
4 1
1 6
6 4
6 1
1 2
2 6
3 5
5 7
7 3
3 7
7 2
2 3
6 2
2 7
7 6
8 4
4 6
6 8

Iniciar sesión para comentar.

 Respuesta aceptada

the cyclist
the cyclist el 26 de Mayo de 2016
Editada: the cyclist el 26 de Mayo de 2016
Trying to piece together all the guesses that these kind volunteers have made in trying to help you. Does this do what you want?
A = [0 2 4; 5 0 4];
At = A';
chunkSize = size(A,2);
shiftedIndex = bsxfun(@plus,mod(1:chunkSize,chunkSize)',[0:chunkSize:numel(At(:))-chunkSize]) + 1;
B = [At(:) At(shiftedIndex(:))]
[ EDIT: I changed this code to correspond to what I wrote in my comment below. Given the new information you provided, I think this is correct.]

7 comentarios

Ali
Ali el 26 de Mayo de 2016
Many thanks the cyclist. I wrote it wrong.
I have a matrix with 260 row and 3 columns. I would like to produce a matrix with 780 row and 2 columns. for instance:
A=[0 2 4; 5 0 4]
I would like to have something like this: [0 2] [2 4] [4 2] [5 0] [0 4] [4 5]
the cyclist
the cyclist el 26 de Mayo de 2016
It is still not easy to interpret what you have, and what you want. You have not defined the rule to get from one to the other.
Please tell us the rule, so we don't have to keep guessing.
the cyclist
the cyclist el 26 de Mayo de 2016
Editada: the cyclist el 26 de Mayo de 2016
Here is my new best guess at what you want:
A = [0 2 4; 5 0 4];
At = A';
chunkSize = size(A,2);
shiftedIndex = bsxfun(@plus,mod(1:chunkSize,chunkSize)',[0:chunkSize:numel(At(:))-chunkSize]) + 1;
B = [At(:) At(shiftedIndex(:))]
Ali
Ali el 26 de Mayo de 2016
Editada: Ali el 26 de Mayo de 2016
i have a text file which I have to convert it in another text file with different format. I read the data from the text file and i want to write it in another way. in file, i read a matrix with 260 row and 3 columns. now i want to write it with 780 rows and 2 columns.
this is a piece of the file :
1 0 2
0 3 2
4 1 6
6 1 2
3 5 7
this is the final format that i need
0: 1 0
1: 0 2
2: 2 1
3: 0 3
4: 3 2
5: 2 0
6: 4 1
7: 1 6
8: 6 4
9: 6 1
10: 1 2
11: 2 6
12: 3 5
13: 5 7
14: 7 3
the cyclist
the cyclist el 26 de Mayo de 2016
Editada: the cyclist el 26 de Mayo de 2016
So, it looks like the rule is what Joseph Cheng guessed. For each
row = [r1 r2 r3]
you want that converted to
M = [r1 r2
r2 r3
r3 r1];
and then for each row, keep appending to the bottom of M.
That is what my code does.
Ali
Ali el 26 de Mayo de 2016
Many thanks for the help.
what about the number in front of each row?
for instance:
1: 0 2
tnx again
Ali
Ali el 26 de Mayo de 2016
Thanks a lot the cyclist!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Preguntada:

Ali
el 26 de Mayo de 2016

Comentada:

Ali
el 26 de Mayo de 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by