필터 지우기
필터 지우기

suppressing output from user defined function

조회 수: 88 (최근 30일)
Michael
Michael 2016년 3월 25일
댓글: Voss 2024년 2월 25일
function f=fib(n);
f=ones(n,1);
for i=1:n-2;
f(i+2,1)=f(i+1,1)+f(i,1);
end;
i have this function to calculate fibbonaci sequence, but i get outputs despite having semicolons on everything.
Can anyone tell me why?

채택된 답변

Jonathan Chin
Jonathan Chin 2016년 3월 25일
When you call your function use a semi colon at the end of the function to suppress the output.
try f=fib(n) and f=fib(n); in the command line to see the results
  댓글 수: 1
Michael
Michael 2016년 3월 25일
편집: Michael 2016년 3월 25일
worked. i'm an idiot -_- Thanks man.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2016년 3월 25일
You have to put a semi-colon in the line that calls fib() to prevent the default output
abc = fib(19)
fib is called and returns an expression that is assigned to the variable, but the default action for assignment is to also display the result of the assignment. You would need
abc = fib(19);
to suppress it.
This is not under the control of the called function, which does not have control by the time MATLAB makes the decision about whether to output or not.
  댓글 수: 5
Yevgeniy Gorbachev
Yevgeniy Gorbachev 2024년 2월 25일
@Voss Exactly the behavior I'm looking for, thank you!
Voss
Voss 2024년 2월 25일
You're welcome!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by