Info
此问题已关闭。 请重新打开它进行编辑或回答。
Arrange Matrix - Each Column Values to a new row
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!