Filter löschen
Filter löschen

writetable adds unnecessary columns to Excel file

5 Ansichten (letzte 30 Tage)
Thomas Kirsh
Thomas Kirsh am 6 Aug. 2020
Kommentiert: Thomas Kirsh am 7 Aug. 2020
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.

Akzeptierte Antwort

Image Analyst
Image Analyst am 6 Aug. 2020
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 Kommentar
Thomas Kirsh
Thomas Kirsh am 7 Aug. 2020
It seems that's what happened. After deleteing the files manually and running my code again, the extra columns don't appear. Thank you.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by