Writetable for different data to same file

조회 수: 14 (최근 30일)
CH
CH 2021년 8월 5일
편집: CH 2021년 8월 6일
Hello,
I have a script that reads in a csv file and outputs a number of variables. I then store this variable in a table with two headings, the name of the file and in this case Time to Completion.
varNames = {'File','Time to Completion)'};
T = table(Name,TTC,'VariableNames',varNames);
writetable(T,'Time_Completion.xls');
My problem is that I want to use this same file (Time_Completion.xls) for different runs of the script with new data so that the columns populate with every new run rather than overwriting. I don't know to read the file every time it opens and if there's data in one row go down and fill the next. Appreciate any help. Thanks.

답변 (1개)

Cris LaPierre
Cris LaPierre 2021년 8월 5일
See the Append Data to Bottom of Table example on the writetable documentation page.
  댓글 수: 6
CH
CH 2021년 8월 5일
편집: CH 2021년 8월 6일
So if I change my line of code to include that line the error I get is below. Matlab version is 2021a
writetable(T,'Time_Completion.xls','WriteMode','Append');
Error using table (line 264)
Invalid parameter name: WriteMode.
Cris LaPierre
Cris LaPierre 2021년 8월 5일
Do you get an error when you run the following?
InsectSpecies = {'Monarch Butterfly';'Seven-spot Ladybird';'Orchid Mantis';...
'American Bumblebee';'Blue Dasher Dragonfly'};
InsectOrder = {'Lepidoptera';'Coleoptera';'Mantodea';'Hymenoptera';'Odonata'};
InsectFamily = {'Nymphalidae';'Coccinellidae';'Hymenopodidae';...
'Apidae';'Libellulidae'};
PredatoryInsect = logical([0;1;1;0;1]);
T = table(InsectSpecies,InsectOrder,InsectFamily,PredatoryInsect)
writetable(T,'InsectCollection.xls','WriteRowNames',true)
%% Now append a new row to the table
newInsect = table({'Red-banded leafhopper'},{'Hemiptera'},{'Cicadellidae'},logical([0]));
writetable(newInsect,'InsectCollection.xls','WriteMode','Append',...
'WriteVariableNames',false,'WriteRowNames',true)

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by