How to use xlswrite instead of fwrite ?
1 回表示 (過去 30 日間)
古いコメントを表示
hi..below code is to fetch files and append in separate excel file..i done..but existing is getting saved from A1(first row),but i need to write my data's from 3rd,(starts form C1)..I couldnt bring it..help with this code..
pathName = 'F:\test folder\run\';
fileList = dir(fullfile(pathName, '*.run'));
out = fopen(fullfile(pathName, 'append.xlsx'), 'w');
for k = 1:numel(fileList)
s = fileread(fullfile(pathName, fileList(k).name));
fwrite(out, s,'char');
end
fclose(out);
0 件のコメント
回答 (2 件)
dpb
2013 年 8 月 14 日
To use xlswrite would have to convert the input to numeric array and if is mixed won't work.
Probably simplest if the above is working for your purposes other than not having the leading blank lines would be to just prepend them before writing the first actual data--
...
out = fopen(fullfile(pathName, 'append.xlsx'), 'w');
% write the N empty lines...
N=2; % say, pick a number
fprintf(out,repmat('\n',1,N)); % N newlines to the file first
for k = 1:numel(fileList)
...
0 件のコメント
Image Analyst
2013 年 8 月 15 日
In the loop, call xlswrite() to write out the data, but first you need to put it into a cell array. Everything that you want to be in its own cell in Excel has to be in a single cell in your cell array. Read this for an explanation: http://matlab.wikia.com/wiki/FAQ?&cb=7634#What_is_a_cell_array.3F. But it's important to keep track of how many rows your cell array is so that you can increment the output row, otherwise everything will just overwrite starting at cell A1. If you have lots of files, you'd best learn ActiveX programming because it will be much faster. Search the forum for ActiveX - it's not that hard to learn and you'll have much much faster code.
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!