MATLAB: Use indeces of a column to sort another column

cell array of stringsindexing

Hi, I have a cell array of strings A like this:
'2' '8Bm'
'3' '11l'
'4' 'CE'
'5' '14r'
'6' 'v23a'
'7' 'Ia'
'8' '13b'
'9' 'Ld'
'10' '36c'
'11' '24a'
'13' 'AAA'
'14' '10mc'
I need to sort the the second column according to the indeces present in the first column. The resulting array B should be like this:
[]
'8Bm'
'11l'
'CE'
'14r'
'v23a'
'Ia'
'13b'
'Ld'
'36c'
'24a'
[]
'AAA'
'10mc'
where B(1) and B(12) are missing because the indeces 1 and 12 were not present in A(:,1). Thank you!

Best Answer

indices = str2double(A(:, 1));
B = cell(max(indices), 1);
B(indices) = A(:, 2)