ARGCHK

バージョン 1.0.0.0 (4.93 KB) 作成者: J De Freitas
Validates parameters passed to a function.
ダウンロード: 793
更新 2005/8/2

ライセンスがありません

ARGCHK validates parameters passed to a function.

[ErrorMsg, ErrorNo] = ARGCHK(ParmSpec,FuncName)
returns an error message if any input parameter to the function
FuncName does not meet the specification as set by ParmSpec.

ParmSpec = {x, data type, range, severity, name}

x = parameter to be checked
data type 'real', 'integer', 'scalar', 'string', 'vector', or 'matrix'
range = [a b]; a = lower limit; b = upper limit
severity = 'warning' or 'error'
name = string identifying parameter x e.g. 'X' or 'pCheck'

See ARGCHK help for more details.

Example,

function [a,b] = pol2car(x,y,str)
% This function takes two values x and y and converts them into
% Polar coordinates, a and b if str = 'polar' or into Cartesian
% coordinates if str = 'cartesian'.

error(nargchk(3, 3, nargin)); % check number of input arguments

p(1,:) = {x 'real' [0 1E6] 'warning' 'x'};
p(2,:) = {x 'scalar' [] 'warning' 'x'};
p(3,:) = {y 'real' [0 1E6] 'error' 'y'};
p(4,:) = {y 'scalar' [] 'error' 'y'};
p(5,:) = {str 'string' [{'polar'} {'cartesian'}] 'error' 'str'};

% p is the parameter specification

[ErrorMsg, ErrorNo] = argchk(p,'pol2car');
if isempty(char(ErrorMsg))
switch str
case 'polar'
a = sqrt(x^2 + y^2);
b = angle(x+j*y);
case 'cartesian'
a = x*cos(y);
b = x*sin(y);
end
else
a = [];
b = [];
for i = 1:length(ErrorMsg)
disp([num2str(ErrorNo(i)),' ', char(ErrorMsg(i))]);
end
end

The following errors are returned when the function is incorrectly called with:

>> [u,v] = pol2car(-2,[1:8],'artesian');
1 POL2CAR ERROR: Input parameter x must be between 0 and 1000000.
4 POL2CAR WARNING: Input parameter y must be scalar.
5 POL2CAR ERROR: Input parameter str must be an exact string match.

引用

J De Freitas (2024). ARGCHK (https://www.mathworks.com/matlabcentral/fileexchange/7949-argchk), MATLAB Central File Exchange. 取得済み .

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

Community Treasure Hunt

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

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

Update