xlswrite: write values in different rows in each iteration in Excel file
26 ビュー (過去 30 日間)
古いコメントを表示
hi, i need doing xlswrite: write values in different rows starting from A2,A3... An, if assume A1 for the title each coulmn
eaxmple : in Excel file the storing values as following :
Row1 sim_seconds' ,'simtickx'
Row 2 223 33
row3 12 55
i attached data sets and the code :
clc;
clear all;
xlfiles = dir('*.xlsx'); % You are in the folder of xl files
Nfiles = length(xlfiles) ; % number of xl files
% loop for each file
for i = 1:Nfiles
fname = xlfiles(i).name ; % file name
[~,~,dat] = xlsread(fname) ; % read the file
%%do what you want %%%
p= strcmp(dat(:,1),'sim_ticks') ;
a(i)= cell2mat(dat(p,2));
p1= strcmp(dat(:,1),'sim_insts') ;
b(i) = cell2mat(dat(p1,2));
data= [ a (i), b(i)];
xlswrite('A.xlsx',data,'Sheet1','A2'); %Write data
end
col_header={'sim_seconds','simtickx'}; %Row cell array (for column labels)
xlswrite('A.xlsx',col_header,'Sheet1','A1'); %Write column header
how can put rows sequence A1, A2, A3 ... Ai , changing based on iteraion value as example : xlswrite('A.xlsx',data,'Sheet1','A( i) ');
0 件のコメント
採用された回答
Image Analyst
2019 年 11 月 25 日
Try this
cellReference = sprintf('A%d', i);
xlswrite('A.xlsx', data, 'Sheet1', cellReference);
or better yet just store in a cell array and call just xlswrite just once:
INSIDE the loop, stuff values into the ith row of the cell array:
ca{i, 1} = a(i);
ca{i, 2} = b(i);
AFTER the loop, call xlswrite():
cellReference = sprintf('A2');
xlswrite('A.xlsx', ca, 'Sheet1', cellReference); % Write out ca, not data.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Spreadsheets についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!