How to use xlswrite instead of fwrite ?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (2)
dpb
il 14 Ago 2013
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 Commenti
Image Analyst
il 15 Ago 2013
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 Commenti
Vedere anche
Categorie
Scopri di più su Spreadsheets in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!