Error using function: Not enough input arguments.
古いコメントを表示
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.
採用された回答
その他の回答 (1 件)
You have to call the function with an argument n:
>> myfirstmatlab(4)
Note that you can write your program in a single line
S = sum(1:n);
カテゴリ
ヘルプ センター および File Exchange で MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!