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.

 Réponse acceptée

Star Strider
Star Strider le 30 Avr 2015
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 commentaires

GGT
GGT le 30 Avr 2015
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 le 4 Déc 2019
Modifié(e) : Akhil George Thomas le 4 Déc 2019
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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB Coder dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by