Borrar filtros
Borrar filtros

How to use xlswrite instead of fwrite ?

2 visualizaciones (últimos 30 días)
sandy
sandy el 14 de Ag. de 2013
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);

Respuestas (2)

dpb
dpb el 14 de Ag. de 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)
...

Image Analyst
Image Analyst el 15 de Ag. de 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.

Categorías

Más información sobre Use COM Objects in MATLAB en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by