필터 지우기
필터 지우기

Using the save/append function

조회 수: 3 (최근 30일)
Theodore
Theodore 2013년 7월 15일
Hello! I'm trying to write a code where I read in a few .xls files and have them convert the date into a vector(s) and have those vectors added back to the file. My code is currently:
source_dir = '/Users/student/Documents/MATLAB/RAWS Station Data'; % Source directory
dest_dir = '/Users/student/Documents/MATLAB/RAWS Results'; % Result Destination directory
source_files = dir(fullfile(source_dir, '*.xls')); %Locates all .xls files
n=length(source_files); %total length of RAWS files to be used in loop
for i=1:n
a = xlsread(source_files(i).name);
savefile= source_files(i).name
d = a(:,1);
ds = datestr(d,2); %Converts numeric Matlab code for dates back into original format
date = datevec(ds) %Puts date into vector defined as YYYY/MM/DD
date(:,4:6)=[];
save(savefile,'date','-append')
end
I'm currently getting the error: Error using xlsread (line 247) File contains unexpected record length. Try saving as Excel 98.
Any thoughts? Thanks!
  댓글 수: 1
dpb
dpb 2013년 7월 16일
What ver ML and Excel?
I presume that simply the
a = xlsread(source_files(i).name);
line is the only one that matters in the posting as far as the error???
Have you tried the suggested workaround from the error message?
--

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

채택된 답변

Jan
Jan 2013년 7월 16일
There are two types of files using .xls as file extension:
  1. Tab separated Text files (you can read them in the editor)
  2. Binary files which are opened by Excel
For both types save is not appropriate for writing or appending. Either dlmwrite or xlswrite are better.
  댓글 수: 1
Theodore
Theodore 2013년 7월 16일
Thanks again Jan! I really appreciate it!

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by