MATLAB: How to label sorted variables

sort

Hi,
Let say I have a matrix obtained from sort function,
x = [1,1,3;
2,2,1;
3,3,2]
with 1, 2, and 3 represent sorted values of certain variables in vertical manner alongside each column. I want to have another variable that stores the label of corresponding order.
% (e.g. It will be like this)
y = [A,A,B]
How can I do this if I have 7 variables that I want to sort in a 7-by-m matrix?
Thank you.

Best Answer

Maybe what you want:
>> labels=string({"A","B","C"});
>> x = [1,1,3;
2,2,1;
3,3,2];
>> labels(x)
ans =
3×3 string array
"A" "A" "C"
"B" "B" "A"
"C" "C" "B"