필터 지우기
필터 지우기

Excel sheet creation error

조회 수: 1 (최근 30일)
Isao Okada
Isao Okada 2017년 9월 4일
댓글: Isao Okada 2017년 9월 4일
An Excel workbook can be created by writetable() command. When I overwrite with the same name Excel file but with different length data, the old data in the excel sheet still remains.
In an example below, after creating Excel sheet with len=100, I overwrite data made by len=10;
However, row 12 to row 101 data in the sheet remain the same as before. This R12 to R101 data should be deleted. I want to solve this issue.
Example
% ExcelWrite.m
len = 100; % 10; << change length;
fr = (1:len)';
ga =zeros(len,1);
ph = zeros(len,1);
for i=1:len
ga(i) = i+3.4;
ph(i)= i*2+80-50.6*2;
end
%%Excel sheet write
T = table( fr, ga, ph,'VariableNames',{'Fre','gain','ph'});
filename = strcat('data','1','.xls');
writetable(T,filename,'sheet',1,'Range','A1');

채택된 답변

Image Analyst
Image Analyst 2017년 9월 4일
Before writetable(), add these 4 lines
recycle('on');
if exist(filename, 'file')
delete(filename);
end
  댓글 수: 1
Isao Okada
Isao Okada 2017년 9월 4일
I got a good result of which I desired by your answer. Thank you so much.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 ファイルの操作에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!