フィルターのクリア

Function output name unused

4 ビュー (過去 30 日間)
Ji Li
Ji Li 2018 年 9 月 19 日
コメント済み: Ji Li 2018 年 9 月 19 日
I specified a function whose output is named 'finalOutputs', every time I run the function, it populates an output without the name but 'ans'. When I debug it line by line, it works well and returns the output in 'finalOutputs' matrix, but once I exit debugger, another matrix 'ans' appeared. Why does this happened? I'm new to Matlab and really confused about it.
function [finalOutputs] = func(input1, input2,...)
  1 件のコメント
Stephen23
Stephen23 2018 年 9 月 19 日
編集済み: Stephen23 2018 年 9 月 19 日
An example of calling a function with one output:
myOutput = func(...)
The name you use for that output is independent of any name used inside the function. Note that the introductory tutorials explain how to call function with outputs:
Doing the introductory tutorials is much more efficient then guessing how MATLAB works.

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

採用された回答

Walter Roberson
Walter Roberson 2018 年 9 月 19 日
When you execute the function, the local variable finalOutputs will get assigned to. However, that does not affect any variables in the workspace of the caller of the function. The calling function needs to deliberately assign the output to some variable (which might have a completely different name.)
MATLAB function inputs and outputs are handled positionally not by name.
  3 件のコメント
Stephen23
Stephen23 2018 年 9 月 19 日
編集済み: Stephen23 2018 年 9 月 19 日
"...I call ‘run func’"
Then func is not a function, because (as its help clearly states) run only runs scripts. Scripts can create variables in the same workspaces that they are called from, but they do not have input/output arguments.
Ji Li
Ji Li 2018 年 9 月 19 日
Thank you so much!

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by