Create New Arrange of a Matrix - Rearrange Matrix

조회 수: 1 (최근 30일)
Juan Pablo
Juan Pablo 2019년 12월 15일
댓글: Star Strider 2019년 12월 18일
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

채택된 답변

Star Strider
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
Juan Pablo
Juan Pablo 2019년 12월 18일
Thanks for your help!, I didn't know it about that function, it was very helpful!
Star Strider
Star Strider 2019년 12월 18일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by