So for example I have
1st column | 2nd column
1 1
1 3
1 9
2 4
2 7
I want to convert it to
1st column | 2nd column | 3rd column | 4th column
1 1 3 9
2 4 7 3
The (3,4) element should be empty.
I can do it by Matlab using for and if but it takes too much time for huge data, so I need a more elegant and brilliant idea.
I prefer Matlab but other languages are ok. (I can export the matrix to csv or xlsx or txt and use the other languages, if that language can solve my problem.)
Thank you in advance!
[Updates]
If
A = [2 3 234 ; 2 44 33; 2 12 22; 3 123 99; 3 1232 45; 5 224 57]
1st column | 2nd column | 3rd column
2 3 234
2 44 33
2 12 22
3 123 99
3 1232 45
5 224 57
then running
[U ix iu] = unique(A(:,1) ); r= accumarray( iu, A(:,2:3), [], @(x) {x'} )
will show me the error
Error using accumarray
Second input VAL must be a vector with one element for each row in SUBS, or a
scalar.
I want to make
1st col | 2nd col | 3rd col | 4th col | 5th col | 6th col| 7th col
2 3 234 44 33 12 22
3 123 99 1232 45
5 224 57
How can I do this? Thank you in advance!
3
, while the output has two. Which element is supposed to end up where? – Schorschfor
loop, but we may be able to help improve what you have. – David K