MATLAB: How to change a cell in a string to a string in a table

data formatMATLABtableunique

Hey everyone, I'm trying to use the 'unique' matlab function.
unique(table.row)
When I try this I get the error "Cell array input must be a cell array of character vectors.". I think this is because my table is in the form
table.row(1) = {'string'}
But it needs to be in the form
table.row(1) = 'string'.
I tried to fix this by using the for loop below
for n= 1:numel(table.row)
table.row(n)=table.row{n};
end
but doing this I get the output error "Conversion to cell from char is not possible."

Best Answer

% This reproduces your error
T = table(num2cell(string(['a':'z']')),'VariableNames',{'row'});
unique(T.row) % ERROR!
% Convert from cellarray of strings vectors to string array
T = table(num2cell(string(['a':'z']')),'VariableNames',{'row'});
T.row = [T.row{:}]'; % *


unique(T.row) %class: string
% Do that twice to convert to characters
T = table(num2cell(string(['a':'z']')),'VariableNames',{'row'});
T.row = [T.row{:}]'; % *
T.row = [T.row{:}]'; % *
% Alternative: T.row = convertStringsToChars(T.row); % r2017b **
unique(T.row) %class: char
Notes
* if there is a missing value in T.row, this will break.
** Will not break if there are missing values in T.row