Error When Using Writetable Function

조회 수: 19 (최근 30일)
Jonathan Pinko
Jonathan Pinko 2020년 6월 22일
댓글: Tommy 2020년 6월 23일
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 9x1 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
  댓글 수: 1
Tommy
Tommy 2020년 6월 22일
편집: Tommy 2020년 6월 23일
For reference, here's what getReport() returns for the error you got, assuming I did get the same the error:
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.
Error in tabular/writeXLSFile (line 132)
newVarj(:,cnt+(1:num)) = newVarjj;
Error in table/write (line 211)
writeXLSFile(t,fname,ext(2:end),otherArgs);
Error in writetable (line 155)
write(a,filename,varargin{:})
Error in [my file] (line 9)
writetable(ResultsTable,'CodeResults.xlsx');

댓글을 달려면 로그인하십시오.

채택된 답변

Tommy
Tommy 2020년 6월 23일
편집: Tommy 2020년 6월 23일
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');
  댓글 수: 4
Jonathan Pinko
Jonathan Pinko 2020년 6월 23일
This works perfectly, thanks again.
Tommy
Tommy 2020년 6월 23일
Awesome, happy to help!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by