How to overwrite my data everytime I run my code?

조회 수: 13 (최근 30일)
KD
KD 2024년 8월 13일
댓글: Walter Roberson 2025년 3월 30일
I'm currently writing a program and everytime I run it, it just adds the data to the excel vs deleting the contents of the excel and replacing it with new data. I'm using the writetable function which I thought would automatically clear the excel before filling it with new data. Any ideas?

채택된 답변

Hassaan
Hassaan 2024년 8월 13일
% Your data table
data = table(...); % Replace with your actual data
% Delete the existing file (if it exists)
if exist('your_file.xlsx', 'file')
delete('your_file.xlsx');
end
% Write the data to an Excel file and overwrite it
writetable(data, 'your_file.xlsx', 'WriteMode', 'overwrite');
  댓글 수: 3
Image Analyst
Image Analyst 2025년 3월 30일
@Jørgen Are you using Windows? If so you can use ActiveX. See attached for a bunch of Excel utilities.
Walter Roberson
Walter Roberson 2025년 3월 30일
When you call writetable(), specify 'WriteMode', 'overwritesheet'

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by