Create New Arrange of a Matrix - Rearrange Matrix
3 ビュー (過去 30 日間)
古いコメントを表示
Hi Guys,
I am trying to put in a new arrangement the 3-column matrix that is on the left to the new arrangement in the right (7-column matrix). The numbers in the 2nd column are the ones that I need to distribute in the new matrix. The 1st and the 3rd column are the references for further distribution.
The numbers in the 3rd column are always the same (1 to 6). The numbers of the 1st column can increase, but in this case, it is only until 4.
Sometimes there is more than one option for each par:
Cell 2 and Reference 1 = 7 and 8,
Cell 3 and Reference 2 = 6 and 7,
and that is the main problem that I have for trying to get this new arrangement.
I appreciate your help if you want to help me with it.
Thanks for your time and help.
![D2 (3).png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/254567/D2%20(3).png)
0 件のコメント
採用された回答
Star Strider
2019 年 12 月 15 日
I created values for your data, since I do not have the original values.
Try this:
Col1 = repmat((1:4), 5, 1);
Col1 = Col1(:);
Col3 = randi(6, 20, 1);
Col2 = randi(23, 20, 1);
Mtx = accumarray([Col1 Col3], Col2, [], @(x){x});
Out = cell2table(Mtx, 'VariableNames',{'1','2','3','4','5','6'}, 'RowNames',{'1','2','3','4'})
producing (for this run):
Out =
4×6 table
1 2 3 4 5 6
________________ ________________ ________________ ____________ ____________ ________________
1 {[ 7.0000e+000]} {[22.0000e+000]} {[22.0000e+000]} {0×0 double} {2×1 double} {0×0 double }
2 {0×0 double } {0×0 double } {2×1 double } {3×1 double} {0×0 double} {0×0 double }
3 {[16.0000e+000]} {2×1 double } {[17.0000e+000]} {0×0 double} {0×0 double} {[13.0000e+000]}
4 {[16.0000e+000]} {[ 3.0000e+000]} {3×1 double } {0×0 double} {0×0 double} {0×0 double }
2 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Cell Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!