factorial command wont accept the input of n in () and keeps asking for n

1 次查看(过去 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
  1 个评论
John D'Errico
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
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
/MATLAB/toolbox/matlab/specfun/factorial.m

类别

Help CenterFile Exchange 中查找有关 Timing and presenting 2D and 3D stimuli 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by