フィルターのクリア

Im writing a script to iterate through factorials, while storing each factorial in an array. Why does it keep saying there aren't enough inputs?

1 回表示 (過去 30 日間)
Sorry, I'm new to matlab, heres the code: %% Function to compute the factorial n! function s = myfact(n) % input n, output z s(1) = 1; s=zeros(1,n); for k=2:n s(k) = s(k-1)*k;
end end
It's fine until I publish it, at which point it says: Not enough input arguments.
Error in myfact (line 4) for k=2:n. Can someone help?

回答 (1 件)

Cam Salzberger
Cam Salzberger 2017 年 10 月 11 日
編集済み: Cam Salzberger 2017 年 10 月 11 日
Hey Matthew,
When you publish a file, it's similar to clicking the "run" button. If you haven't provided an input to your function ("n") which uses it, that's the error message you'll get. If you want to publish it, it'd suggest either making it a local function to a script, or just turning the function into a script for publishing, and defining "n" within the script.
-Cam

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by