...
Now enter the above three statements in the editor (you can be lazy like me and copy-and-paste from the Command History; hold down the Ctrl-key to select multiple statements simultaneously). In addition add the clear all and clc commands at the top to start with a clean slate.
Save this file: File > Save
Enter beam.m
for File name. M-Files need to have .m as the suffix. Make sure you are saving into your working directory. Click Save.
...