필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
Christopher Madico
Christopher Madico 2021년 11월 11일
답변: Sahil Jain 2021년 11월 15일
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에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by