how to save in specific row and column with this code in excel?
15 visualizzazioni (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)
David Sanchez
il 13 Ago 2013
To write in a precise cell within a xls file, use the built-in function xlswrite, which gives that feature.
Example from documentation:
Write mixed text and numeric data to testdata2.xls, starting at cell E1 of Sheet1:
d = {'Time','Temperature'; 12,98; 13,99; 14,97};
xlswrite('testdata2.xls', d, 1, 'E1')
David Sanchez
il 13 Ago 2013
Instead of writing values one at a time on each iteration, you should better save the values in an array and then write the whole array into the *.xls file. It's much faster than writing to the .xls on each iteration.
3 Commenti
David Sanchez
il 13 Ago 2013
From your code, it is not easy to see what your variable(s) will be. I would go to
doc xlswrite
to see the full documentation and some examples. I am sure you will adapt them to your needs.
My example:
y = zeros(3); % initialization of final matrix
for k=1:3
x=rand(3,1); % array random numbers
y(:,k) = x; % copy previous array to kth column of the matrix
end
xlswrite('my_xls.xls',y,'B2'); % write the matrix to xls file, starting in cell 'B2'.
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!