Create New Arrange of a Matrix - Rearrange Matrix
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Juan Pablo
le 15 Déc 2019
Commenté : Star Strider
le 18 Déc 2019
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 commentaires
Réponse acceptée
Star Strider
le 15 Déc 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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Cell Arrays dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!