how to save each iteration values without overwriting in a loop ?

1 回表示 (過去 30 日間)
sandy
sandy 2013 年 8 月 12 日
hi, i spliting strings into cell array and storing of each value in each cell in MS excel is done..but while coming to do same for many files in loop and append them .i couldnt move ahead..stuck here..help needed plz
TESTDATA_20120807_1826 0 +1.107672E+1 +6.204607E+0 +1.513477E+1
..i need to do 10 files and need to append in excel file..i tried, stuck here in writing to my output file ..help needed
pathName = 'F\run\';
fileList = dir(fullfile(pathName, '*.run'));
out = fopen(fullfile(pathName, 'append.xls'), 'w');
for k = 1:numel(fileList)
s = fileread(fullfile(pathName, fileList(k).name));
a=regexp(s,' ','split');
b=a(~cellfun(@isempty ,a));
fwrite(out, b, 'char');
end
fclose(out);

回答 (1 件)

Walter Roberson
Walter Roberson 2013 年 8 月 12 日
fprintf() instead of fwrite(), and be sure to insert the delimiters between the fields. Or are you trying to write a binary .xls file? If so then do not try to use fwrite() yourself for that purpose: use xlswrite()
  2 件のコメント
sandy
sandy 2013 年 8 月 13 日
if i use fprintf.it showing error like,the values from fprintf is not going to the file identifier of the output file. also im trying to write ascii file to excel.my each input files contain lines like, ex: TESTDATA_20120807_1806 0 +1.107672E+1 +6.204607E+0 +1.513477E+1 TESTDATA_20120807_1816 0 +2.107672E+1 +6.206607E+0 +1.510477E+1 TESTDATA_20120807_1826 0 +6.107672E+1 +6.208607E+0 +1.513477E+1
i couldnt write each lines above in excel in a loop after fetching from my each input files.plz code for above ex: ,that should get each file in loop and append in excel file with delimited.
thanks in advance.
sandy
sandy 2013 年 8 月 14 日
i cant save each iteration values using fprintf in my code...help needed.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by