Example: We create a short script that calculates the circumference of a circle:
radius = 3;
circumference = 2 * pi * radius
If we ran this script, we would find that radius
would be set to 3 and circumference
to 18.85 in our workspace. But what if we wanted to easily modify the value of radius
, to test the effect of different values on the resulting circumference
value? This is where functions come in handy. We could define a function find_circumference
that computes the circumference of a circle with given radius, as follows:
[circumference] = function find_circumference(radius)
circumference = 2 * pi * radius;
end