What do the empty square brackets [] do in the expression executed by eval?

137 ビュー (過去 30 日間)
Geoff Inge
Geoff Inge 2019 年 9 月 5 日
編集済み: Guillaume 2019 年 9 月 5 日
sys = eval([model '(0,[],[],''compile'')']);

採用された回答

Stephen23
Stephen23 2019 年 9 月 5 日
編集済み: Stephen23 2019 年 9 月 5 日
"What do the empty square brackets [] do in the expression executed by eval?"
Nothing really.
MATLAB has positional input arguments. Many MATLAB functions use an empty numeric array (i.e. []) to indicate that an input argument is undefined, which allows further input arguments to be specified. In your example the 2nd and 3rd arguments are undefined, whilst the 1st and 4th arguments have defined values (i.e. 0 and the char vector 'compile' respectively).
That is all.
Read the function/model documentation to know if [] is accepted as an undefined positional input argument.
This has nothing to do with eval.

その他の回答 (1 件)

Guillaume
Guillaume 2019 年 9 月 5 日
編集済み: Guillaume 2019 年 9 月 5 日
The same as they always do, concatenate whatever is inside the bracket. model must contain a char vector, so it just appends (0, [], [], 'compile') to whatever is in model.
A much better way of doing the same:
sys = feval(model, 0, [], [], 'compile');
don't use eval!
edit: completely misread the question. As Stephen explains, the brackets inside the call are used to tell the function called by eval to use the default value for that particular input.

カテゴリ

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

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by