Effacer les filtres
Effacer les filtres

Using the save/append function

3 vues (au cours des 30 derniers jours)
Theodore
Theodore le 15 Juil 2013
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 commentaire
dpb
dpb le 16 Juil 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?
--

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 16 Juil 2013
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 commentaire
Theodore
Theodore le 16 Juil 2013
Thanks again Jan! I really appreciate it!

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by