Using the save/append function
3 次查看(过去 30 天)
显示 更早的评论
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
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
2013-7-16
There are two types of files using .xls as file extension:
- Tab separated Text files (you can read them in the editor)
- Binary files which are opened by Excel
For both types save is not appropriate for writing or appending. Either dlmwrite or xlswrite are better.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!