Documentation

Sort Ordinal Arrays

This example shows how to determine sorting order for ordinal arrays.

Load sample data.

AllSizes = {'medium','large','small','small','medium',...
            'large','medium','small'};

The created variable, AllSizes, is a cell array of strings containing size measurements on eight objects.

Create an ordinal array.

Convert AllSizes to an ordinal array with levels small < medium < large.

AllSizes = ordinal(AllSizes,{},{'small','medium','large'});
getlevels(AllSizes)
ans = 

     small      medium      large 

Sort the ordinal array.

When you sort ordinal arrays, the sorted observations are in the same order as the category levels.

sizeSort = sort(AllSizes);
sizeSort(:)
ans = 

     small 
     small 
     small 
     medium 
     medium 
     medium 
     large 
     large 

The sorted ordinal array, sizeSort, contains the observations ordered from small to large.

See Also

Related Examples

More About

Was this topic helpful?