We call this as Script or function

1 回表示 (過去 30 日間)
matlabgeek
matlabgeek 2016 年 1 月 19 日
コメント済み: matlabgeek 2016 年 1 月 19 日
Function has input and output. If it is only has input or only has output, we called this script or still function?

採用された回答

dpb
dpb 2016 年 1 月 19 日
It is a function if the m-file beginning line contains the keyword function, otherwise it's a script. Scripts and functions Of course, if a function has no inputs and no outputs it's likely not of a lot of value unless it's reading/writing files or doing something else with side effects on the system as, having it's own workspace, anything being done inside it won't ever show up after it has completed its execution. Barring, of course, the use of assignin, evalin, etc., which are able to get access to the main workspace from a function, but use of those should be reserved for very special circumstances indeed.

その他の回答 (1 件)

per isakson
per isakson 2016 年 1 月 19 日
A script operates in the workspace of the caller, e.g. the base workspace. It may use existing variables and may create new variables - in the workspace of the caller.
A function operates in its own workspace. A declaration statement, ... function(...), must be the first executable line of the function. It may have input and/or output arguments, or no arguments, e.g
function HelloWorld()
disp('Hello world')
end
  1 件のコメント
matlabgeek
matlabgeek 2016 年 1 月 19 日
Thanks for your detailed explanation. I appreciate it

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by