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!