Info
This question is closed. Reopen it to edit or answer.
Arrange Matrix - Each Column Values to a new row
1 view (last 30 days)
Show older comments
sourceData = {1 'ABC1';3 'ABC2'; 8 'ABC1'; 7 'ABC3'; 0 'ABC1'; ...
5 'ABC3'; 8 'ABC2'; 4 'ABC3'; 7 'ABC2'; 6 'ABC2'} ;
[names, ~, cId] = unique( sourceData(:, 2) ) ;
buf = bsxfun( @eq, 1:max( cId ), cId ) ;
rId = sum( cumsum( buf ) .* buf, 2 ) ;
destData = [names.'; cell( max( rId ), numel( names ))] ;
destData(sub2ind( size(destData), 1+rId, cId )) = sourceData(:, 1) ;
This leads to:
>> destData
destData =
'ABC1' 'ABC2' 'ABC3'
[ 1] [ 3] [ 7]
[ 8] [ 8] [ 5]
[ 0] [ 7] [ 4]
[] [ 6] []
This code was by Cedric Wannaz http://de.mathworks.com/matlabcentral/answers/171993-arrange-matrix-same-values-of-a-row-to-one-column
Now I want to swap each column to a row, so that the result looks like:
destData =
'ABC1' [ 1] [ 8] [ 0] []
'ABC2' [ 3] [ 8] [ 7] [ 6]
'ABC3' [ 7] [ 5] [ 4] []
How can I do that ?
0 Comments
Answers (1)
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!