function output = addTwo(input)
% This function will add the input with 2
output = 2 + input;In Matlab interactive mode, type:
>> addTwo(3)
ans 5
The function also can have more than one input and output arguments. Save this code to addThen.m:
function [add,dot] = addThen(input)
% This function will add and also will multiply
% the input arguments.
add = input + input;
dot = input * input;
Then in Matlab IDE, type
>> [a,b] = addThen(4)
a = 8
b = 16
No comments:
Post a Comment