How to use xlswrite instead of fwrite ?
조회 수: 2 (최근 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에서 Use COM Objects in MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!