combineOpt

バージョン 1.3.0.0 (2.06 KB) 作成者: Andrey Popov
Combine user provided option's structure with a default one
ダウンロード: 876
更新 2011/11/6

ライセンスの表示

options = combineOpt (user_options, default_options)

The function allows easy definition and submission of options to a Matlab function.
combineOpt combines the fields of the structure user_options with the fields of the default_options's structure, during which the fields of user_options overwrite the fields of default_options.

Example:
>> user_options.B = 5;
>> user_options.C = 'foo';

>> default_options.A = 1;
>> default_options.B = 0;

>> options = combineOpt (user_options, default_options)
options =
A: 1
B: 5
C: 'foo'

The function can be very useful when there are many optional arguments that can be passed to a function. A useful structuring of one's function is

function y = myfunct(x, opt)
def_options = struct('a',5,'b',0);

if nargin == 0 % return the default options
y = def_options;
return
else
opt = combineOpt (opt, def_options)
end

% further code

end % function

引用

Andrey Popov (2024). combineOpt (https://www.mathworks.com/matlabcentral/fileexchange/21424-combineopt), MATLAB Central File Exchange. 取得済み .

MATLAB リリースの互換性
作成: R2006a
すべてのリリースと互換性あり
プラットフォームの互換性
Windows macOS Linux
カテゴリ
Help Center および MATLAB AnswersStructures についてさらに検索
謝辞

ヒントを与えたファイル: fireFly

Community Treasure Hunt

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

Start Hunting!
バージョン 公開済み リリース ノート
1.3.0.0

Fixed typo

1.2.0.0

Updated author information

1.1.0.0

Updated license in the M file

1.0.0.0