MATLAB: Do I get NaNs when I try to enter characters in the UITABLE object

MATLAB

I create a uitable as follows:
u=uitable('Data',cell(3,1),'ColumnEditable',[true],'ColumnFormat',{'char'});
When I attempt to type characters in the uitable, the result stored in the 'Data' property of the uitable is 'NaN' even though I had specified the column format to accept characters.

Best Answer

This is the expected behavior when there is a "mis-match" between the Data property's type and the ColumnFormat property. In the example above, Data is a numeric type (cell(3,1) creates three empty numeric matrices) but ColumnFormat is being set to 'char'. A table in the following documentation page describes the expected behavior for all the possible combination of Data types and ColumnFormat settings:
To avoid this mis-match, in this case you should initialize the Data property of the uitable with a cell array of empty strings as follows:
data(1:3,1) = {''};
u=uitable('Data',data,'ColumnEditable',[true],'ColumnFormat',{'char'});