This happens because of the presence of the 'newline' character in the character vector variable 'text1'.
You can use the 'strtrim' function to get rid of the 'newline' characters at the start or end of the character vector.
This will display the contents of the character vector in the MATLAB Workspace and in the 'uitable' cell.
Hence, modifying the given code as follows fixes the issue:
f = figure;
uit = uitable(f);
text1 = strtrim(['ab cd ef g' newline]);
text2 = 'ab cd ef gh';
text3 = '01234567891';
d = {text1,52,true;
text2,40,true;
text3,25,false};
uit.Data = d;
Note that this will only work for 'newline' characters at the start and end of character vectors.
If you have 'newline' characters somewhere in the middle of your character vectors, you will need to use the 'regexprep' to search and replace the 'newline' chars.
This can be done as follows:\ntext1 = regexprep(text1,'[\n\r]+','');
text1 = regexprep(text1,'\n','');
Refer to the following MATLAB Answers link for a more detailed discussion on the topic of erasing 'newline' characters from strings in MATLAB:
Best Answer