Creating a triangle function file
1 回表示 (過去 30 日間)
古いコメントを表示
I have to do the following, no real idea what to do?
" Create a function file “e83.m” that can be called with variable number of input arguments. It could be 1,2 or 3 arguments. They are the sides in a triangle with a 90 degree angle. If one argument is given, then assume it is the hypotenuse and calculate the other sides by assuming they are of equal length. If two arguments are given, assume the longest is the hypothenuse and calculate the remaining one. If three values are given, check if they represent a proper right angled triangle, and output an error if not. “error(‘values not consistent with right-angled triangle’);” Your m-file should of course cope with error inputs by generating proper errors. Possible errors it should detect are: a) Wrong number of input arguments b) Non-numeric input arguments c) Non-scalar input arguments (matrices for example, hint: length(in) == 1) "
Thanks for any help
0 件のコメント
回答 (1 件)
Image Analyst
2013 年 6 月 14 日
Some partial code that you can build upon:
function output = e83(varargin)
% Test code
% test1(42);
% test1(42, 69);
% test1('42', 69, pi);
fprintf('Number of input arguments = %d\n', nargin)
output = 42; % Initialize
if nargin == 1
n1 = varargin{1}
elseif nargin == 2
[n1, n2] = varargin{:}
elseif nargin == 3
[n1, n2, n3] = varargin{:}
if ~isnumeric(n1)
error('n1 is not numeric')
end
end
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Operators and Elementary Operations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!