function ToTecplot3D(p,t,Usum,filename) % --------- p should be 3*N or N*3 ---------------------------- % --------- T should be 4*N or N*4 or 8*N or N*8---------------------------- % --------- U should be 1*N or 1*N or 0 ----------------------- % --------- filename should be as 'xxx.txt' or 'xxx' ---------- if size(p,1)==3 flag_p=1; elseif size(p,2)==3 p = p'; else msgbox('坐标p应该是3×N,未输出文件','错误') return end if size(t,1)==8 || size(t,1)==4 flag_t = 1; elseif size(t,2)==8 || size(t,2)==4 t = t'; else msgbox('单元t应该是4×N 或 8×N,未输出文件','错误') return end if Usum ==0 Usum = ones(1,size(p,2)); elseif size(Usum,1)==1 flag_t = 1; elseif size(Usum,2)==1 Usum = Usum'; else msgbox('位移U应该是1×N,未输出文件','错误') return end if ~ismember('.',filename) filename = [filename,'.txt']; end fid=fopen(filename,'w'); fprintf(fid,'TITLE = "Example: Xdd1997 Data" '); fprintf(fid,'VARIABLES = "X", "Y","Z","Displacement" '); % lineseg, tringle, quadrilateral tetrahedron, or brick if size(t,1) == 4 fprintf(fid,'ZONE N = %d E = %d ET = tetrahedron F=FEPOINT ',size(p,2),size(t,2)); else fprintf(fid,'ZONE N = %d E = %d ET = Brick F=FEPOINT ',size(p,2),size(t,2)); end CD_results=[p;Usum]; fprintf(fid,'%16.9f %16.9f %16.9f %16.9f ',CD_results); if size(t,1) == 4 fprintf(fid,'%d %d %d %d ',t); else fprintf(fid,'%d %d %d %d %d %d %d %d ',t); end fclose(fid); disp([filename,' 文件输出成功'])