Write a function that will receive a variable number of input arguments: the length and width of a rectangle, and possibly also the height of a box that has this rectangle as its base
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:10| Question number:12.10
All Answers
total answers (1)
boxcalcs.m
function [area, varargout] = boxcalcs(len, wid, varargin)
% Calculates a rectangle area and possibly also a
% height of a box and returns the area and possibly volume
% Format of call: boxcalcs(length, width) or
% boxcalcs(length, width, height)
% Returns area of box and if height is passed, volume
% always return the area
area = len * wid;
n = nargin;
% if the height was passed, return the box volume
if nargin == 3
varargout{1} = area * varargin{1};
end
end
need an explanation for this answer? contact us directly to get an explanation for this answer