why no statistic in workspace

1 回表示 (過去 30 日間)
zilai si
zilai si 2019 年 5 月 21 日
コメント済み: zilai si 2019 年 5 月 21 日
Hello, everyone. I have a strange problem.
I write a function
function cubic_cardinal_Bspline_interpolation(f, x_l, x_r)
and input in the command window:
cubic_cardinal_Bspline_interpolation(@(x)1/(1+x^2), -5, 5)
the function runs normally but the workspace is empty, what's wrong? I suppose all statistics will be recorded in the workspace??
  1 件のコメント
Alex Mcaulley
Alex Mcaulley 2019 年 5 月 21 日
I guess you don't have outputs in this function...

サインインしてコメントする。

回答 (1 件)

Steven Lord
Steven Lord 2019 年 5 月 21 日
Nothing is wrong, this is the expected behavior for functions. From the documentation, "Functions have their own workspace, separate from the base workspace. Therefore, none of the calls to the function triarea overwrite the value of a in the base workspace. Instead, the function assigns the results to variables a1, a2, and a3."
Any variables you define in the workspace of a call to the cubic_cardinal_Bspline_interpolation function remain in that workspace until the function call exits. At that point, any variables you've declared the function to return are returned to its caller and any variables you haven't declared as an output argument cease to exist. [This is a bit of an oversimplification, but I'm trying not to complicate matters too much by getting into the exceptions.] You haven't declared your function to return any output arguments, so its entire workspace gets discarded. As stated on this documentation page:
If there is no output, you can omit it.
function myFunction(x)
This behavior is different than the behavior for scripts, which work directly in the workspace in which they were called (which at the Command Prompt is the base workspace.)
  1 件のコメント
zilai si
zilai si 2019 年 5 月 21 日
thanks a lot!!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by