Matlab Fundamentals

Matlab Script Files (or M-Files)

We can simplify repetitive tasks by storing a series of Matlab commands in a script file (later we will use these to write powerful programs)

  1. Use "New, M-File" under file menu or use any text editor
  2. Type in a series of commands, such as
  3. Save as file name plotgas.m
  4. In the Matlab window, type in plotgas and it will run your series of commands
  5. You can ask the user to enter input by using the input command. Change the definition of n to read
  6. Any text following a percent sign (%) is treated as a comment by Matlab
  7. Look at the definition of the M-File carnot.m to see a more extensive script file

Electronic Copy:
Revised: 28-JAN-97 by Tom Huber, Physics Department, Gustavus Adolphus College.