factorial command wont accept the input of n in () and keeps asking for n
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
John D'Errico
am 11 Nov. 2021
Bearbeitet: John D'Errico
am 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.
Antworten (1)
Sahil Jain
am 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 Kommentare
Siehe auch
Kategorien
Mehr zu Timing and presenting 2D and 3D stimuli 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!