附源程序:
- function mat2ans(filename,x,y,z)
- % 把MATLAB计算的曲线曲面导入ANSYS
- % author:paradiseboy
- % 2004-7-13
- % Henan Polytechnic University
- % www.dytrol.com
- if(ischar(filename)==0)
- error('Invalid filename');
- end
- if(ndims(z)~=2)
- error('Variable z must be a 2-dimensional array');
- end
- if any((size(x)~=size(z))|(size(y)~=size(z))) % size of x or y does not size of z
- if((length(x)==1)&(length(y)==1)) % Must be specifying dx and dy, so make vectors
- dx=x;
- dy=y;
- x=((1:size(z,2))-1)*dx;
- y=((1:size(z,1))-1)*dy;
- end
- if((length(x)==size(z,2))&(length(y)==size(z,1))) % Must be specifying vectors
- xvec=x;
- yvec=y;
- [x,y]=meshgrid(xvec,yvec);
- else
- error('Unable to resolve x and y variables');
- end
- end
- fid=fopen(filename,'w');
- if(fid==-1)
- error(sprintf('Unable to write to %s',filename));
- end
- [m,n]=size(z);
- x=reshape(x',m*n,1);
- y=reshape(y',m*n,1);
- z=reshape(z',m*n,1);
- fprintf(fid,'/prep7\r\n'); % 进入前处理
- % 创建关键点
- for i=1:m*n
- fprintf(fid,'k,%4.d,%.5f,%.5f,%.5f,\r\n',i,x(i),y(i),z(i));
- end
- % 创建样条线
- for i=1:m
- fprintf(fid,'FLST,3,%3.d,3\r\n',n);
- for j=1:n
- fprintf(fid,'FITEM,3,%4.d,\r\n',j+(i-1)*n);
- end
- fprintf(fid,'BSPLIN, ,P51X\r\n');
- end
- % 由蒙皮技术创建面
- fprintf(fid,'FLST,2,%2.d,4\r\n',m);
- for i=1:m
- fprintf(fid,'FITEM,2,%d\r\n',i);
- end
- fprintf(fid,'ASKIN,P51X\r\n');
- fprintf(fid,'ldele,all\r\n');
- fprintf(fid,'kdele,all\r\n');
- fprintf(fid,'aplot\r\n');
- fprintf(fid,'NUMCMP,ALL\r\n');
- fprintf(fid,'FINISH\r\n');
- fclose(fid);
复制代码 |