How do I fix the error Function definitions are not permitted at the prompt or in scripts.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Mallouli Marwa
am 29 Mär. 2016
Bearbeitet: Walter Roberson
am 29 Mär. 2016
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
0 Kommentare
Akzeptierte Antwort
Azzi Abdelmalek
am 29 Mär. 2016
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)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Whos 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!