Page 1 of 1

Functions in MATLAB

Posted: Thu Sep 26, 2024 7:49 am
by amh
1. Create function file

Code: Select all

function x = myfunny(a,b,c)
x = a^2 + 2*b + b*c;
end

2. Enter this in command window

Code: Select all

>> myfunny(1,2,3)

ans =

    11

Anonymous function

Posted: Thu Sep 26, 2024 7:55 am
by amh

Code: Select all

% f = @(arglist)anonymous_function

Code: Select all

f = @(x) x^2 + 2*x;
f(2);
the answer;

Code: Select all

ans = 8