GMgKe586q6suSQnyqZLlGCooeWM

Pages

Search

Wednesday, December 22, 2010

Defining Function In Matlab

Firstly, type this code and then save it - addTwo.m
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
  
    
Share/Bookmark

No comments:

Post a Comment