Example 16.3.1 sphere_vol() in action.
Here is an interactive code box that functions identically to the MATLAB command window.
inputs and outputs.
r = 1:10;
sphere_vol() to calculate the volumes associated with those radii! Exciting
sphere_vol() in action.
radii and volume. You do not need to use these exact variable names when using your function. In this case, we used the variables r for the radii and we stored the volumes in variable v. The internal function variables are just placeholders that tell the function how to manipulate the inputs and where to store the outputs. The names inside the function do not matter to the user.
impact_driver() function into a box, and throwing it in the garage (path).
sphere_vol() function we created will only work if you are currently in the directory that contains the file sphere_vol.m! If we add the folder that sphere_vol.m is contained into the path, we can call the sphere_vol() function from anywhere.
“Functions” and store it somewhere on your computer that you will remember (MyDocuments? Somewhere else? You decide). Then navigate to the folder that contains this new folder in MATLAB. In the “Current Folder” browser you can then right-click on the “Functions” folder, and select the “Add to path >” option. Then select the “Selected Folder and Subfolders” option. Viola! Now any function file inside this particular folder will be accessible regardless of your current working directory. You told MATLAB where to look!