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.
Star Strider
Star Strider 2015 年 4 月 30 日
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?
Star Strider
Star Strider 2019 年 12 月 4 日
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 ExchangeMATLAB 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