I have a table filled with strings and would like to sort the rows by specific strings. Is there a way to use sortrows or sort in order to do that? I am open to all and better ways of doing this. For example:
% Create Data
Position = {'Vice President';'Guest';'Member';'President'};Name = {'John';'Jane';'Nancy';'Bob'};% Turn data into a table
data = table(Position,Name); % Sort rows by President->VP->Member->Guest
%%%% Your Helpful Advice would go here :) %%%%
Desired Output
%{
data = 4×2 table Position Name __________________ _________ {'President' } {'John' } {'Vice President'} {'Jane' } {'Member' } {'Nancy'} {'Guest' } {'Bob' }%}
I originally created a cell array of each position, putting them in the order that I desired, and using sortrows, but couldn't figure out the syntax so, I figured it wasn't possible considering the direction must be 'ascend' or 'descend'.
I could possibly just assign a value to each string using strcmp and a swtich, add that column to the data, then sort the rows by the new column.
Any suggestions are appreciated, thank you!
Best Answer