Trying to create dxf file, but I keep getting error: "Not enough input arguments" - how can I fix it?

3 views (last 30 days)
I attempted to use the function created by Greg Siegel (writedxf):
function[]=writedxf(fname,X,Y,Z)
%
% Given a filename and a 3d line where each line element is
% specified by X,Y, and Z coordinates it writes a DXF file with the
% a connected line and N vertices.
% try at your own risk, refer also to writedxf.m from Greg Siegle
%
fullname=sprintf('%s.dxf',fname);
fid=fopen(fullname,'w');
fprintf(fid,'999\ncreated by Matlab\n 0\nSECTION\n 2\nENTITIES\n 0\n');
for a=1:length(X)-1
fprintf(fid,'LINE\n 8\n 0\n');
%create new line element
fprintf(fid,'10\n %.4f\n 20\n %.4f\n 30\n %.4f\n',X(a),Y(a),Z(a));
%first coordinate triple - starting point of line-element
fprintf(fid,'11\n %.4f\n 21\n %.4f\n 31\n %.4f\n',X(a+1),Y(a+1),Z(a+1));
%second coordinate triple - ending point of line-element
fprintf(fid,' 0\n');
end
fprintf(fid,'ENDSEC\n 0\nEOF\n');
fclose(fid);
I am trying to make a 2D plot of differently spaced grids (I will export it to solidworks). I created a function that could be called in the writedxf file and tried to make a Z output of 0's, but I still receive the message:
monospaced"Not enough input arguments.
Error in writedxf (line 15) fprintf(fid,'10\n %.4f\n 20\n %.4f\n 30\n %.4f\n',X(a),Y(a),Z(a));"
function [X,Y,Z] = vectorizinggrids(space, xangle, yangle)
xangles = [-xangle:space:xangle];
yangles = [-yangle:space:yangle];
X = 228*tan(pi*xangles/180);
Y = 228*tan(pi*yangles/180);
Z = 0*ones(1,length(X));
end
Why do I still get this error and how do I modify it? Any help would be greatly appreciated!

Accepted Answer

Walter Roberson
Walter Roberson on 1 Mar 2018
You are not passing four arguments when you call writedxf . The first has to be the file name; then you have to pass X, Y, and Z.
  2 Comments
Cathy
Cathy on 1 Mar 2018
Edited: Cathy on 1 Mar 2018
I think my problem actually comes from the second function that I listed above. I'm passing
writedxf('tbd',vectorizinggrids(0.1, 20, 20));
I just realized that when I isolate
vectorizinggrids(0.1, 20, 20)
it doesn't display the Z values.
However, when I pass:
[vectorizinggrids(0.1, 20, 20), 0*ones(1,length(X))]
it shows the list of 0's, but when I put this portion back into writedxf, it still says "Not enough input arguments".
Walter Roberson
Walter Roberson on 1 Mar 2018
When you have a function that returns multiple outputs such as your vectorizinggrids, then calling
somefunction(vectorizinggrids(...))
results in all outputs of vectorizinggrids except the first being discarded, and only the first being passed in.
Your code
writedxf('tbd',vectorizinggrids(0.1, 20, 20));
is the same as
[TemporaryVariable, ~, ~] = vectorizinggrids(0.1, 20, 20);
writedxf('tbd', TemporaryVariable);
This behavior of multiple outputs is coded very deep in MATLAB and cannot be gotten around at all. You need to code
[X, Y, Z] = vectorizinggrids(0.1, 20, 20);
writedxf('tbd', X, Y, Z);

Sign in to comment.

More Answers (0)

Categories

Find more on Model Import in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!