MATLAB: Converting cells to strings

cells struct array strings

Actually I have a 1×1 struct that I am extracting data from.
But the data is a mixture of numbers and strings.
I want to convert all of the data into strings so that I could store it in a separate cell array.
'char' doesn't do a good conversion, because it truncates everything to 255.

Best Answer

variant
dc = struct2cell(data);
t1 = cell2mat(cellfun(@(x)[ischar(x) isnumeric(x)],dc,'UniformOutput', false));
celstr = dc(t1(:,1));
num = dc(t1(:,2));
% if there is a field with a cell with characters and numbers
t2 = ~any(t1,2);
dcc = cell(cellfun(@(x)x(:)',dc(t2),'UniformOutput', false));
dcc2 = [dcc{:}];
t3 = cell2mat(cellfun(@(x)[ischar(x) isnumeric(x)],dcc2,'UniformOutput', false)')';
celstr = [celstr;dcc2(t3(1,:))'];
num = [num;dcc2(t3(2,:))'];