getOptions

バージョン 1.0.1 (7.17 KB) 作成者: Biafra Ahanonu
A simple, user friendly way to handle and parse variable argument inputs (varargin) into MATLAB functions.
ダウンロード: 88
更新 2020/5/11

getOptions is a simple, user friendly way to handle and parse variable argument inputs (varargin) into MATLAB functions.

Please see my 2014 write-up (https://bahanonu.com/getOptions) for details and reasons behind implementing and using this function.

Install by adding getOptions directory to path. Usage instructions in getOptions.m, in the README, on GitHub, or briefly below.

===
Instructions on using getOptions.

There are two ways to input options to a function that getOptions will parse. The first involves passing an 'options' parameter with a structure containing all options that the user would like to modify.

Method #1
opts.Option1= 1;
opts.Option2 = 0;
exampleFxn(inputArg1,'options',opts);

The second method involves passing Name-Value arguments as is normal in MATLAB.

Method #2
exampleFxn(inputArg1,'Option1',1,'Option2',0);

Next add getOptions to beginning of a function as below with all options put inside a structure.

function [out1] = exampleFxn(in1,varargin)
% ========================
% FUNCTION OPTIONS
% Description option #1
opts.Option1 = '';
% Description option #2
opts.Option2 = 1;
% Description option #3
opts.Option3 = 1;
% get options
opts = getOptions(opts,varargin); % ***HERE IS WHERE getOptions IS USED***
% disp(opts)
% unpack options into current workspace (not recommended)
% fn=fieldnames(opts);
% for i=1:length(fn)
% eval([fn{i} '=opts.' fn{i} ';']);
% end
% ========================

% Your function
end

引用

Biafra Ahanonu (2024). getOptions (https://github.com/bahanonu/getOptions/releases/tag/v1.0.1), GitHub. 取得済み .

MATLAB リリースの互換性
作成: R2019a
すべてのリリースと互換性あり
プラットフォームの互換性
Windows macOS Linux

Community Treasure Hunt

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

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

See release notes for this release on GitHub: https://github.com/bahanonu/getOptions/releases/tag/v1.0.1

1.0.0

この GitHub アドオンでの問題を表示または報告するには、GitHub リポジトリにアクセスしてください。
この GitHub アドオンでの問題を表示または報告するには、GitHub リポジトリにアクセスしてください。