Error using function: Not enough input arguments.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Astrik
am 5 Aug. 2016
Bearbeitet: John D'Errico
am 5 Aug. 2016
I get the following error every time i try to run a simple function
Not enough input arguments. My code is the following
function S = myfirstmatlab (n )
% gives the sum of the first n integers
S = 0; % start at zero
% The loop :
for i = 1: n % do n times
S = S + i; % add the current integer
end % end of the loop
Can someone help me to figure it out? The answers to similar questions did not help me.
0 Kommentare
Akzeptierte Antwort
John D'Errico
am 5 Aug. 2016
Bearbeitet: John D'Errico
am 5 Aug. 2016
You don't RUN a function.
IMHO, run (or use of it from the menu) is the worst thing they ever introduced into MATLAB, in terms of newbies misusing the tool.
When you write a function, in order to use it, you need to use it at the command line, just as you use ANY OTHER FUNCTION.
So execute a line like this at the commandline:
S = myfirstmatlab(10);
0 Kommentare
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!