필터 지우기
필터 지우기

Writting multiple arrays to an excel spreadsheet after each loop

조회 수: 8 (최근 30일)
Stephen Trainor
Stephen Trainor 2012년 2월 22일
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

답변 (2개)

Tannistha
Tannistha 2012년 2월 23일
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 2012년 2월 23일
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
  댓글 수: 1
Tannistha
Tannistha 2012년 2월 27일
write them in separate cells in a cellarray and then use cell2mat

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by