Functions in MATLAB

MATLAB programming related topics
Post Reply
User avatar
amh
Site Admin
Posts: 263
Joined: Thu Jan 06, 2022 12:35 am

Functions in MATLAB

Post 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
User avatar
amh
Site Admin
Posts: 263
Joined: Thu Jan 06, 2022 12:35 am

Anonymous function

Post 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
Post Reply