Create New Arrange of a Matrix - Rearrange Matrix

5 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Star Strider
Star Strider il 15 Dic 2019
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 Commenti
Juan Pablo
Juan Pablo il 18 Dic 2019
Thanks for your help!, I didn't know it about that function, it was very helpful!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Cell Arrays in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by