9236e8f0-cd5a-42fb-be55-538065ebe453

9236e8f0-cd5a-42fb-be55-538065ebe453 - MATLAB Programming...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
M ATLAB Programming Functions and Scripts While M ATLAB is a powerful environment for command-line numerical analysis, problem solving and data presentation, its true power lies in its programming and scripting environment. This handout summarizes the two major features of this capability and presents several examples. Matlab m-files The basic unit of programming in M ATLAB is the m-file. These are text files containing lists of M ATLAB command that can be invoked, or called, from the command prompt (or from another m-file). M ATLAB has an m-file editor built in and can be invoked from the main tool bar by clicking on the ‘new document’ icon on the left hand side. Before you start the editor, make sure you set the current directory to a directory you have control over. See the figure below: Let’s do a quick example. Once you click on the ‘new file’ icon, the m-file editor comes up with a window that looks like this: Set Current Directory Start the m-file editor
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Let’s enter a few lines that store some variables in the work space and perform a simple operation. File name in title bar line number along left side
Background image of page 2
Two important points to note here. First, you can (and should) embed comments in your script to remind you, or anyone else, what you were attempting to do. M ATLAB uses the % sign to denote a comment. Anything to the right of the % sign will be ignored by M ATLAB but stay in the script. The editor also highlights them as green. Second, note that an asterisk has appeared on the title bar of the window, next to the file name (which has not yet been set). The asterisk indicates that the file in the window contains some changes that have not yet been saved (and, hence, not visible to the M ATLAB environment). This would be a good time to save it. Go to the “Save” menu and
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 9

9236e8f0-cd5a-42fb-be55-538065ebe453 - MATLAB Programming...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online