MATLAB: How to Remove Double Quotes from the Table

quotation markssimple

I started with this seemingly simple problem as a way to learn some new skills in MatLab:
Given a list of names in a cell array, sort the list by the last name. My end-goal was to have a table with two columns, last and first name, sorted by last name. I think I'm close to a solution, but the table output includes double quotation marks. I'd like to understand a simple way of removing the quotation marks.
list = {'Barney Google','Snuffy Smith','Dagwood Bumstead'};
list = list';
list2 = split(list);
T = array2table(list2,...
'VariableNames',{'FirstName','LastName'});
T = sortrows(T,'LastName');

Best Answer

The quotes are a fignewton of the Matlab display formatting; you can't eliminate them from the command window excepting by either writing the string with a formatting expression or via disp or the like...but while the type indicator characters are displayed, they are not part of the data itself. Illustration with a slight modification; use the new(ish) string class instead of cellstr array...
slist = ["Barney Google";"Snuffy Smith";"Dagwood Bumstead"];
T = array2table(split(slist),'VariableNames',{'First','Last'});
>> T.First(1) % observe the " to indicate a string
ans =
"Barney"
>> disp(T.First(1)) % with disp() only the data shown
Barney
>>
>> strfind(T.First(1),'"') % show there's no " stored...
ans =
[]
>>
>> fprintf('%s\n',T.Last(1)) % or write the data; no quotes, either.
Google
>>
The table output format is not intended to be a printed report; it's intended as a working interface to the use of the table and the reminders of the datatype are consistent with the "ordinary" display of similarly-typed variables in the command window.