Why am I getting "not enough input arguments?"

I have a main script and it is using a function like so:
shape=input('What was the shape of the final graph? Enter either square, circle, figure_eight: ')
Final_Data=Save(shape);
FUNCTION FILE:
function [T] = Save(shape)
%SAVE Summary of this function goes here
% Detailed explanation goes here
if shape==square
xT=[xQ1,xQ2,xQ3,xQ4]';
yT=[yQ1,yQ2,yQ3,yQ4]';
T=[xT,yT];
fid=fopen('Final2.dat','w');
save Final2.dat T -ascii -single
st=fclose(fid);
elseif shape==circle
xT=[xQ1,xQ2,xQ3,xQ4]';
yT=[yQ1,yQ2,yQ3,yQ4]';
T=[xT,yT];
fid=fopen('Final2.dat','w');
save Final2.dat T -ascii -single
st=fclose(fid);
else shape=figure_eight
xT=[xQ1,xQ2]';
yT=[yQ1,yQ2]';
T=[xT,yT];
fid = fopen('Final2.dat','w');
save Final2.dat T -ascii -single
st=fclose(fid);
end
end
Every time I run it I keep getting the error "not enough input arguments." Please help.

 채택된 답변

Star Strider
Star Strider 2015년 4월 30일

0 개 추천

You’re comparing strings, so you have to define your matching strings as strings. Also, use strcmp or strcmpi instead of the logical double equal (==). I haven’t looked at the files it created (I’ll leave the QA/QC to you), but this code runs:
function [T] = Save(shape)
%SAVE Summary of this function goes here
% Detailed explanation goes here
Q1 = strcmp(shape,'square')
if strcmpi(shape,'square')
xT=[xQ1,xQ2,xQ3,xQ4]';
yT=[yQ1,yQ2,yQ3,yQ4]';
T=[xT,yT];
fid=fopen('Final2.dat','w');
save Final2.dat T -ascii -single
st=fclose(fid);
elseif strcmpi(shape,'circle')
xT=[xQ1,xQ2,xQ3,xQ4]';
yT=[yQ1,yQ2,yQ3,yQ4]';
T=[xT,yT];
fid=fopen('Final2.dat','w');
save Final2.dat T -ascii -single
st=fclose(fid);
else strcmpi(shape,'figure_eight')
xT=[xQ1,xQ2]';
yT=[yQ1,yQ2]';
T=[xT,yT];
fid = fopen('Final2.dat','w');
save Final2.dat T -ascii -single
st=fclose(fid);
end
end

댓글 수: 4

GGT
GGT 2015년 4월 30일
Thanks for the answer. It makes sense but I keep getting that same error. Ill accept the answer though. I have a feeling something else is wrong with my data.
My pleasure.
I didn’t get that error when I ran it (with my changes) for all options of 'shape'. It ran without errors. (It did not create your ‘Final2.dat’ files, so you may want to save it as a .mat file, that do not require fopen or fclose.)
Run this from the Command Window:
which Save -all
It should only return your function. If it returns something else as well, that means you have ‘overshadowed’ (or ‘shadowed’) your ‘Save’ function. That may be the reason MATLAB is throwing the error.
Akhil George Thomas
Akhil George Thomas 2019년 12월 4일
편집: Akhil George Thomas 2019년 12월 4일
I think I have overshadowed my 'save' function . How do I fix it?
Find it and rename it to something else that is meaningful in the context of your code.
The:
which save -all
command will find it for you if it is a function.
If it is a variable, use the Find function in the MATLAB Editor toolbar (in the NAVIGATE section) to find it.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 MATLAB Coder에 대해 자세히 알아보기

질문:

GGT
2015년 4월 30일

댓글:

2019년 12월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by