% convert phi(nt*tx,ty,nz) to te(cx,cy,6,nz) te=zeros(cx,cy,6,nz); ite=0;jte=1;ntte=1; for i=1:nt il=(i-1)*tx+1; ih=il+tx-1; tepart=phi(il:ih,:,:); ite=ite+1; itel=(ite-1)*tx+1; iteh=itel+tx-1; jtel=(jte-1)*ty+1; jteh=jtel+ty-1; te(itel:iteh,jtel:jteh,ntte,:)=tepart; if iteh == cx ite = 0; jte = jte+1; if jteh == cy jte=1; ntte=ntte+1; end end end