Using the save/append function
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
dpb
am 16 Jul. 2013
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?
--
Akzeptierte Antwort
Jan
am 16 Jul. 2013
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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Spreadsheets finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!