How to overwrite my data everytime I run my code?
5 次查看(过去 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?
0 个评论
采纳的回答
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
2025-3-30
@Jørgen Are you using Windows? If so you can use ActiveX. See attached for a bunch of Excel utilities.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import from MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!