factorial command wont accept the input of n in () and keeps asking for n
1 view (last 30 days)
Show older comments
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
1 Comment
John D'Errico
on 11 Nov 2021
Edited: John D'Errico
on 11 Nov 2021
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.
Answers (1)
Sahil Jain
on 15 Nov 2021
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 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!