- My recommendation is that you always use M files for your Matlab
- To create one, use the "File, New, M-file" menu choice. Then you
would save it, and can reopen it with "File, Open". You should also be
able to double click on the M-file in Windows Explorer, and that will
automatically open Matlab and your M-file.
- You will now have an editor window into which you type commands.
They will not execute until you explicitly try to run them.
- I would recommend putting "clc" as the first line of the file.
This will clear the command window, and any old warnings or output.
- Type commands there just as you would in the command window.
- When you are ready, use the "evaluate cell and advance" button
MATLAB Tips and Resources
- Matlab is case sensitive. While Matlab can deal with "HOURS" and "hours" as two different
variables (because it is case sensitive), you may not be so lucky, so I
would never use those two variables in the same program.
- Think about whether your variables are scalars, vectors, or matrices.
- Variable names, and m-files names, cannot start with a number.
- Matlab may not like file names with a space in them, so avoid them.
- Use the Workspace, which lists all the variables. You can click on
one, and see a table showing the values, and you can compare what Matlab is
computing (based on your code) with what you know it should be.
- If you use functions in external files, you should not rename them.
- Matlab, like most languages, has two kinds of "equal". These often
have different symbols (in Matlab, they are "==" and "=").
- Boolean equality. This tests whether two variables are the same.
- Replace. This takes whatever is in a current memory location, and
replaces it with a new value. This is what we mean with something like
x = x + 1;
Student resources from Mathworks
last revision 1/11/2017