Create matrix with different type of data and sort it based on one of its columns
조회 수: 25 (최근 30일)
이전 댓글 표시
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
채택된 답변
Tommy
2020년 6월 29일
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)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!