How do I convert Matlab script to function

I wrote my script for a class but the next step is to convert that script into a function. What do I type in?

This is my script:

% Find max volume

b = 2.75; %ft for diameter
h = 3.00; %ft for height 

v = (b*h)/3; %ft^3
% use volume to find mass
p = 62.3;

m = p*v;

Solution 1:

The following syntax is used to create a function in MATLAB:

function [y1,...,yN] = myfun(x1,...,xM)

In the example below, the maximumVolume() method takes 3 parameters (b, h, p) and returns the value of the m variable.

result = maximumVolume(2.75, 3.0, 62.3);

function m = maximumVolume(b, h, p)
    v = (b * h)/3;
    m = p * v;
end

References
  • function