MATLAB: Problems with te output of writetable function

export

writetable(E,'FinalMatlab.csv')
I ended up with the attached output. in row 33 the columns were not written completely and instead were written on the next row (before ID 34). Also, it would be great if NaT and Nan could be replaced by empty cells.
Any help would be greatly appreciated

Best Answer

Walter was correct, some of your text fields contain newlines. So, of course, when the newlines are written it messes up the file for some csv readers. Note that any entry with newlines are enclosed in double quotes, so if the parser works detects quoted strings properly it should read the file correctly.
Probably best, is to get rid of these newlines characters. An easy way:
yourtable(:, vartype('cellsttr')) = varfun(@(v) regexprep(v, '[\n\r]', ''), yourtable(:, vartype('cellstr')));
writetable(yourtable, 'something.csv');
You might similarly want to get rid of commas within your text (or replace them with something else), if it's going to confuse your reader.