splitting matrix to different row

1 view (last 30 days)
Ali
Ali on 26 May 2016
Commented: Ali on 26 May 2016
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 Comments
Ali
Ali on 26 May 2016
Edited: Ali on 26 May 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]
the cyclist
the cyclist on 26 May 2016
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

Sign in to comment.

Accepted Answer

the cyclist
the cyclist on 26 May 2016
Edited: the cyclist on 26 May 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 Comments
Ali
Ali on 26 May 2016
Many thanks for the help.
what about the number in front of each row?
for instance:
1: 0 2
tnx again
Ali
Ali on 26 May 2016
Thanks a lot the cyclist!

Sign in to comment.

More Answers (0)

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!