factorial command wont accept the input of n in () and keeps asking for n
3 次查看(过去 30 天)
显示 更早的评论
The factorial comand keeps ignoring the inpu I put in brakets and repeteadly asks for n and I can't figure out why. Its really annoying because whenever I put factorial in a script, it completely ignores the values that the script inputs and keeps asking for n, rendering the script useless.
essentialy what I want to happen is
factorial(5)
ans=120
what happens is
factorial(5)
n= input
ans = input!
so if I do factorial(5) but input 3 upon it asking for n I get 6 instead of 120
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/797459/image.png)
1 个评论
John D'Errico
2021-11-11
编辑:John D'Errico
2021-11-11
The crystal ball is sooooo foggy today. We need to read your mind, or at least see magically into your computer, because we do not see your code. I tried, really, I did, but that blasted crystal ball just keeps telling me that I will soon inherit some money. Or maybe it is telling me that my descendents will soon inherit some money. Drat. I hope it is the former case.
Seriously, we cannot know what your code is doing wrong without seeing your code. It sounds like you wrote a function called factorial. And of course, MATLAB sees that first, before it sees the regular function of that name. But without seeing what you wrote, how can we know?
Anyway one thing you do NOT want to do is write functions with names that overload the names of existing functions. If you do that, then you will see all sorts of bugs happening. so calling your function factorial was just a bad idea.
回答(1 个)
Sahil Jain
2021-11-15
Hi Christopher, the MATLAB "factorial" command does not prompt for inputs. It looks like there's another "factorial" function on the MATLAB path which is being executed. Try using the "which" command to determine which factorial function is being run.
which factorial
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!