Writting multiple arrays to an excel spreadsheet after each loop

6 views (last 30 days)
I am trying to write several arrays into a single excel spreadsheet so that I can manipulate the data and create graphs of it. The arrays are all calculated in a single loop and the data must be written to the excel file each time. It would be convenient if each set of data from each loop was done row by row in excel so I would know which incement the data corresponded to. This is the code
for i=2:hsize+1;
epsglo_top=epsmid+(hh(i-1)*curv)
epsglo_bottom=epsmid+(hh(i)*curv)
epsglo_middle=(epsglo_bottom+epsglo_top)/2
sigmaglo_top=Qbar(:,:,i-1)*epsglo_top
sigmaglo_bottom=Qbar(:,:,i-1)*epsglo_bottom
sigmaglo_middle=(sigmaglo_top+sigmaglo_bottom)/2
m=cos(fibre_radians(i-1));
n=sin(fibre_radians(i-1));
epslocal_top=T*epsglo_top
epslocal_bottom=T*epsglo_bottom
epslocal_middle=(epslocal_top+epslocal_bottom)/2
sigmalocal_top=T*sigmaglo_top
sigmalocal_bottom=T*sigmaglo_bottom
sigmalocal_middle=(sigmalocal_bottom+sigmalocal_top)/2
xlswrite('globalstrain.xls', epsglo_top, 'A1');
xlswrite('globalstrain.xls', epsglo_middle, 'B1');
xlswrite('globalstrain.xls', epsglo_bottom, 'C1');
end
Thanks for the help

Answers (2)

Tannistha
Tannistha on 23 Feb 2012
Instead of writing each array every single time using xlswrite, why don't you store each set of data in a another matrix and then write the whole matrix at once in excel sheet? it will also save time.
mymatrix=zeros(hsize-1,3)
for k=1:hsize-1
%your code
mymatrix(k,1)=epslocal_top;
mymatrix(k,2)= epslocal_middle;
mymatrix(k,3)=epslocal_bottom);
end
xlswrite('myfile',mymatrix,'mysheet','A1');

Stephen Trainor
Stephen Trainor on 23 Feb 2012
the reason i cant do it this was is beacause epslocal_top, epslocal_bottom, epslocal_middle are all 3x1 matrices and i cant put them in another array

Products

Community Treasure Hunt

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

Start Hunting!