writetable adds unnecessary columns to Excel file

5 次查看(过去 30 天)
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 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by