フィルターのクリア

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 Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by