MATLAB: Error When Using Writetable Function

cell2tablewritetable

Hi All,
I have the following code:
f={tSampleName cMeasuredFo cMeasuredD56Fe cMeasuredD26Mg cFeUncertainty cMgUncertainty cFeInterp cMgInterp cMagmaMgNum cOlivineFo cTemperature cDtrsquared cDiffusionCoef cyears1mm cyears2mm cyears3mm cyears4mm cyears5mm};
ResultsTable=cell2table(f);
writetable(ResultsTable,'CodeResults.xlsx');
In which all the inputs to f are 9×1 cells. When I try and run this code, I receive the following error message:
Error using writetable
Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 1-by-9.
Could someone please tell me what I'm doing wrong here? I would like to create a table in excel that shows all of my information stored in ResultsTable.
Thanks,
Jonathan

Best Answer

It seems like writetable() has trouble handling the case where a variable in your table contains a cell which itself contains an Nx1 cell array. Does it work if you concatenate your original cell arrays using square brackets?
f=[tSampleName cMeasuredFo cMeasuredD56Fe cMeasuredD26Mg cFeUncertainty cMgUncertainty cFeInterp cMgInterp cMagmaMgNum cOlivineFo cTemperature cDtrsquared cDiffusionCoef cyears1mm cyears2mm cyears3mm cyears4mm cyears5mm];
ResultsTable=cell2table(f);
writetable(ResultsTable,'CodeResults.xlsx');
(edit)
This results in the error:
T = table({num2cell(1:9)'});
writetable(T,'CodeResults.xlsx');
This doesn't:
T = table({num2cell(1:9)});
writetable(T,'CodeResults.xlsx');