필터 지우기
필터 지우기

writetable adds unnecessary columns to Excel file

조회 수: 5 (최근 30일)
Thomas Kirsh
Thomas Kirsh 2020년 8월 6일
댓글: Thomas Kirsh 2020년 8월 7일
I'm trying to save my table to an Excel spreadsheet.
test_limits = {'1', '2', '3'};
test_sens = {'0.54(0.02)', '0.89(0.01)', '0.34(0.01)'};
test_auc = {'0.78(0.04)', '0.91(0.02)', '0.64(0.02)'};
test_table = table(test_limits', test_sens', test_auc', 'VariableNames', {'Threshold', 'Sensitivity', 'AUC'});
writetable(test_table, 'test_table.xlsx')
However, when I open the file, the table is saved properly in the first 3 columns, but there are 6 more columns called "Sensitivity_1", "Sensitivity_2", "Sensitivity_3", "AUC_1", "AUC_2", "AUC_3" with the corresponding inputs in row format.
Why are these extra columns being added? I've tried transposing the variable name cell array but that doesn't change the results. I couldn't find any similar answers anywhere here.

채택된 답변

Image Analyst
Image Analyst 2020년 8월 6일
I see no such extra columns. Are you sure they're not still existing from a prior run where you forgot to transpose the variables while creating the table? It will just blast over cells, and any in there from a prior run will still be there. You might want to delete the workbook before you call writetable
fileName = 'test_table.xlsx';
if isfile(fileName)
delete(fileName);
end
writetable(test_table, fileName);
  댓글 수: 1
Thomas Kirsh
Thomas Kirsh 2020년 8월 7일
It seems that's what happened. After deleteing the files manually and running my code again, the extra columns don't appear. Thank you.

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by