ATLAB에서 계산된 커브 서피스를 ANSYS로 가져오기
function mat2ans(filename,x,y,z)
% MATLAB ANSYS
t=0:pi/10:2*pi;
[x,y,z]=cylinder(2+cos(t));
filename=strcat('c1.txt');
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
');
%
for i=1:m*n
fprintf(fid,'k,%4.d,%.5f,%.5f,%.5f,\r
',i,x(i),y(i),z(i));
end
%
for i=1:m
fprintf(fid,'FLST,3,%3.d,3\r
',n);
for j=1:n
fprintf(fid,'FITEM,3,%4.d,\r
',j+(i-1)*n);
end
fprintf(fid,'BSPLIN, ,P51X\r
');
end
%
fprintf(fid,'FLST,2,%2.d,4\r
',m);
for i=1:m
fprintf(fid,'FITEM,2,%d\r
',i);
end
fprintf(fid,'ASKIN,P51X\r
');
fprintf(fid,'ldele,all\r
');
fprintf(fid,'kdele,all\r
');
fprintf(fid,'aplot\r
');
fprintf(fid,'NUMCMP,ALL\r
');
fprintf(fid,'FINISH\r
');
fclose(fid);
작성자: LiW