2D-graph data import from MATLAB to AutoCAD
This is an early version and very old program which I coded about 10 years ago. According to the attached pictures it's clear how to use it. I deliberately made such an examples to show the efficiently of Mat2CAD function while dealing with Inf and NaN.
This is an early version and very old program which I coded about 10 years ago. According to the attached pictures it's clear how to use it. I deliberately made such an examples to show the efficiently of Mat2CAD function while dealing with Inf and NaN.
function Mat2CAD(x,y,fname)
%MAT2CAD Converting of MATLAB 2D-graph data to AutoCAD script file.
% MAT2CAD(X,Y,FNAME) creates an AutoCAD script file from data vectors
% X and Y. X and Y must be vector arrays with the same length. They may
% contain Inf and/or NaN.
% FNAME is the Output Script File Name, with extension scr.
% This function is using just AutoCAD pline command for plotting.
%
% Numerical Recipes for Solving Engineering Problems using MATLAB
% By: Mehdi Mosafer, Rev. 0.1, 2001.
% http://matlab1st.blogspot.com
L=length(x);
j1=find(isinf(y));
j2=find(isnan(y));
j=[j1(:);j2(:)];
fid=fopen([fname,'.scr'],'wt');
fprintf(fid,'pline\n');
for k=1:L
if ~isempty(find(k==j))
fprintf(fid,'\n');
fprintf(fid,'pline\n');
else
fprintf(fid,'%g',x(k));
fprintf(fid,',');
fprintf(fid,'%g\n',y(k));
end
end
fprintf(fid,'\n');
fprintf(fid,'zoom\n');
fprintf(fid,'extents\n');
fprintf(fid,'\n');
fclose(fid);
%MAT2CAD Converting of MATLAB 2D-graph data to AutoCAD script file.
% MAT2CAD(X,Y,FNAME) creates an AutoCAD script file from data vectors
% X and Y. X and Y must be vector arrays with the same length. They may
% contain Inf and/or NaN.
% FNAME is the Output Script File Name, with extension scr.
% This function is using just AutoCAD pline command for plotting.
%
% Numerical Recipes for Solving Engineering Problems using MATLAB
% By: Mehdi Mosafer, Rev. 0.1, 2001.
% http://matlab1st.blogspot.com
L=length(x);
j1=find(isinf(y));
j2=find(isnan(y));
j=[j1(:);j2(:)];
fid=fopen([fname,'.scr'],'wt');
fprintf(fid,'pline\n');
for k=1:L
if ~isempty(find(k==j))
fprintf(fid,'\n');
fprintf(fid,'pline\n');
else
fprintf(fid,'%g',x(k));
fprintf(fid,',');
fprintf(fid,'%g\n',y(k));
end
end
fprintf(fid,'\n');
fprintf(fid,'zoom\n');
fprintf(fid,'extents\n');
fprintf(fid,'\n');
fclose(fid);
No comments:
Post a Comment