How can save cell array (numbers and string ) using xlswrite ?
1 次查看(过去 30 天)
显示 更早的评论
hi, i have this code, i tried to store the cell arry (Bandwidth1) in excel file inside iteraion , but the excel file results empty vaule !
lfiles = 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
p2= strcmp(dat(:,1),'sim_seconds') ;
simsecond (i)= cell2mat(dat(p2,2));
dcachmi= strcmp(dat(:,1),'system.cpu00.dcache.overall_misses::total') ;
dcachemi00 = cell2mat(dat(dcachmi,2)) ;
dcachmi= strcmp(dat(:,1),'system.cpu01.dcache.overall_misses::total') ;
dcachemi01 = cell2mat(dat(dcachmi,2)) ;
dcachmi= strcmp(dat(:,1),'system.cpu02.dcache.overall_misses::total') ;
dcachemi02 = cell2mat(dat(dcachmi,2)) ;
dcachmi= strcmp(dat(:,1),'system.cpu03.dcache.overall_misses::total') ;
dcachemi03 = cell2mat(dat(dcachmi,2)) ;
dcachmi= strcmp(dat(:,1),'system.cpu04.dcache.overall_misses::total') ;
dcachemi04 = cell2mat(dat(dcachmi,2)) ;
dcachmi= strcmp(dat(:,1),'system.cpu05.dcache.overall_misses::total') ;
dcachemi05 = cell2mat(dat(dcachmi,2)) ;
dcachmi= strcmp(dat(:,1),'system.cpu06.dcache.overall_misses::total') ;
dcachemi06 = cell2mat(dat(dcachmi,2)) ;
dcachmi= strcmp(dat(:,1),'system.cpu07.dcache.overall_misses::total') ;
dcachemi07 = cell2mat(dat(dcachmi,2)) ;
dcachmi= strcmp(dat(:,1),'system.cpu08.dcache.overall_misses::total') ;
dcachemi08 = cell2mat(dat(dcachmi,2)) ;
dcachmi= strcmp(dat(:,1),'system.cpu09.dcache.overall_misses::total') ;
dcachemi09 = cell2mat(dat(dcachmi,2)) ;
dcachmi= strcmp(dat(:,1),'system.cpu10.dcache.overall_misses::total') ;
dcachemi10 = cell2mat(dat(dcachmi,2)) ;
dcachmi= strcmp(dat(:,1),'system.cpu11.dcache.overall_misses::total') ;
dcachemi11 = cell2mat(dat(dcachmi,2));
dcachmi= strcmp(dat(:,1),'system.cpu12.dcache.overall_misses::total') ;
dcachemi12 = cell2mat(dat(dcachmi,2)) ;
dcachmi= strcmp(dat(:,1),'system.cpu13.dcache.overall_misses::total') ;
dcachemi13 = cell2mat(dat(dcachmi,2)) ;
dcachmi= strcmp(dat(:,1),'system.cpu14.dcache.overall_misses::total') ;
dcachemi14 = cell2mat(dat(dcachmi,2)) ;
dcachmi= strcmp(dat(:,1),'system.cpu15.dcache.overall_misses::total') ;
dcachemi15 = cell2mat(dat(dcachmi,2)) ;
dcachemitotal(i)=dcachemi15+dcachemi14+dcachemi13+dcachemi12+dcachemi11+dcachemi10+dcachemi09+dcachemi08+dcachemi07+dcachemi06+dcachemi05+dcachemi04+dcachemi03+dcachemi02+dcachemi01+dcachemi00;
Bw1(i)= (dcachemitotal(i)*64);
Bw(i)= Bw1(i) ./simsecond (i);
Bandwidth1= sizeconvert ([Bw(i)]) ;
%%%%%%%%%%%%% this is my question %%%%%%%%%%%%%%%%
ca{i, 1} = Bandwidth1; % how can save this array in the Excel file ?
end
col_header={'Bandwidthsize'};
xlswrite('B.xlsx',col_header,'Sheet1','A1');
cellReference = sprintf('A2');
xlswrite('B.xlsx', ca, 'Sheet1', cellReference);
2 个评论
Stephen23
2019-11-26
编辑:Stephen23
2019-11-26
Using numbered variables is a sign that you are doing something wrong.
Copy-and-pasting code is a sign that you are doing something wrong.
Rather than this copy-and-paste fifteen times:
dcachmi= strcmp(dat(:,1),'system.cpu00.dcache.overall_misses::total') ;
dcachemi00 = cell2mat(dat(dcachmi,2)) ;
dcachmi= strcmp(dat(:,1),'system.cpu01.dcache.overall_misses::total') ;
dcachemi01 = cell2mat(dat(dcachmi,2)) ;
...
you should use a loop with:
- sprintf to generate those character vectors, and
- indexing to store the result in one vector or matrix,
then this incredible line of code:
dcachemitotal(i)=dcachemi15+dcachemi14+dcachemi13+dcachemi12+dcachemi11+dcachemi10+dcachemi09+dcachemi08+dcachemi07+dcachemi06+dcachemi05+dcachemi04+dcachemi03+dcachemi02+dcachemi01+dcachemi00;
becomes one simple sum operation.
回答(1 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!