フィルターのクリア

How do I fix the error Function definitions are not permitted at the prompt or in scripts.

1 回表示 (過去 30 日間)
Hello,
Whenever I create a function on matlab, an error message appears as follows:
Error: Function definitions are not permitted at the prompt or in scripts.
For example this function which finds the factorial of an integer:
n=[1:100];
function [y] = fact(n)
if(n<=1)
y=1;
else
y=n*fact(n-1)
end

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 3 月 29 日
Write this part of code and save it as fact.m
function y = fact(n)
if n<=1
y=1;
else
y=n*fact(n-1)
end
then call this function in Matlab Windows Command
n=5
out=fact(n)

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by