Create matrix with different type of data and sort it based on one of its columns
25 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Mona Al-Kharraz
il 29 Giu 2020
Commentato: Mona Al-Kharraz
il 29 Giu 2020
I have two different arrays, one of them is string array and the other is double array. I want to concatenate them and sort the new matrix by the second column (double array)
0 Commenti
Risposta accettata
Tommy
il 29 Giu 2020
For the following example:
% example...
A = strings(10,1);
B = rand(10,1);
you could use a table:
% combine and sort...
T = table(A, B);
sortedT = sortrows(T, 'B')
or a cell array (although I'd probably consider the table to be the better option):
% combine and sort...
C = [cellstr(A), num2cell(B)];
sortedC = sortrows(C, 2)
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Resizing and Reshaping Matrices 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!