MATLAB: Sort categorical variables in an alphabetical order MATLAB I have a set of categorical variables A = {'NY','Boston'} How can one sort A to B as B = {'Boston','NY'} I tried sort but does not work. Best Answer As Ive Ive suggested: the sort function will do what you need:B = categorical({'NY','Boston'});sort(B)ans = 1×2 categorical array Boston NY Related SolutionsMATLAB: Does “sortrows” not work with a semicolon Remember, sortrows(P,-1); would sort the rows and then would throw away the results because you did not write them to a variable. MATLAB: Sorting the variables in cells try this is codes = {'du';'dd';'uu';'ud'};r2 = r;for jj = 1:numel(r2) q = r2{jj}(3:end,2); [i1,i1] = ismember(q,s); [i2,i2] = sort(i1); r2{jj} = r2{jj}([1:2,i2(:)'+2],:);end Related QuestionAlphabetical random permutationSort unique string/number column based on last 2 charactersSorting a matrix alphabeticUnique values in cell array
Best Answer