suppressing output from user defined function
101 ビュー (過去 30 日間)
古いコメントを表示
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?
0 件のコメント
採用された回答
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 件)
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!