MATLAB Scripts

From ControlTheoryPro.com

Jump to: navigation, search
Symbol.gif
MATLAB Scripts
Green carrot left.gif
All MATLAB Articles MATLAB Functions
Green carrot.jpg
In order to prevent spam, users must register before they can edit or create articles.


1 Introduction to MATLAB Scripts

Scripts are a type of m-file that runs in the current workspace. So if you call a script from the command line (base workspace) the script will use and manipulate the variables of the base workspace. This can get very messy and lead to all sorts of strange errors when loops are involved and the coder is lazy about about naming their loop variables (i.e. for i = 1:10, if every loop uses i, j, or k then it's likely that any script called from a loop will alter the loop variable).

2 Requirements

Scripts must be stored in m-files but have few restrictions past that. Scripts cannot have the keyword function anywhere in them. Arguments are not passed to or from a script since it works in the current workspace. The current workspace must have whatever variable the script requires already defined.

Scripts are often created by copying large portions of the command history after a successful manual operation. They allow for repetitive tasks so long as the user provides some sort of wrapper function or script around the repetitive script. For example, if you have telemetry the variable names in each data file will always be the same so it's easy to write a wrapper function that takes in the data file name, loads the file and processes that data using a script.