how to save in specific row and column with this code in excel?
8 ビュー (過去 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 件)
David Sanchez
2013 年 8 月 13 日
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
2013 年 8 月 13 日
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 件のコメント
David Sanchez
2013 年 8 月 13 日
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'.
参考
カテゴリ
Help Center および File Exchange で Spreadsheets についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!