Tips of Programming
It is a powerful research assistance tool with various functions and tookits, so the best way to grasp Matlab is to use it. Write down the tips you dicover or learn yourself, and after a while you will find yourself an expert of Matlab.


1 Comments:
Deal With the Input and Output Arguments
- Use nargin and nargout to determine the number of input and output arguments.
- Use the nargchk and nargoutchk to verify the number of input and output arguments.
- Example (find the minimum number)
function [x,y,z] = myarg(a, b, c, d)
disp(nargchk(2, 4, nargin)) % Allow 2 to 4 inputs
disp(nargoutchk(0,2,nargout)) % Allow 0 to 2 ouputs
x = a;
if (a > b)
x = b;
end
if nargin == 4
y = c;
if (c > d)
y = d;
end
z = x;
if x > y
z = y;
end
else
y = x;
z = x;
end
Post a Comment
<< Home