MATLAB: Difference between num2cell(1:4)’ and {‘1′,’2′,’3′,’4′}’

table

Hi,
I am having an error on creating a table with 'RowNames' property.
truc=array2table([-0.013 -0.470 0.109
-0.013 -0.454 0.107
-0.012 -0.437 0.104
0.009 0.077 -0.088],'VariableNames',{'Scx','SczF','SczR'},'RowNames',num2cell(1:4)');
Main error is: The RowNames property must be a cell array, with each element containing one nonempty character vector.
>> num2cell([1 2 3 4])'
ans =
4×1 cell array
[1]
[2]
[3]
[4]
>> {'1','2','3','4'}'
deux =
4×1 cell array
'1'
'2'
'3'
'4'
In both case it is a cell array, but the content is different.

Best Answer

The simplest way to convert numbers to strings or char arrays since R2016b is:
string(1:15) %that's it!
In earlier versions:
sprintfc('%d', 1:15) %undocumented function!
arrayfun(@num2str, 1:15, 'UniformOutput', false) %using only documented functions