05 Writing Programs and Functions

05 Writing Programs and Functions - 5 - Writing Programs...

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

View Full Document Right Arrow Icon
Functions - 1 5 - Writing Programs and Functions Writing MATLAB Programs When you type in commands at the >> prompt, you are using the MATLAB command window. Once the commands have been typed, you cannot easily go back and re-execute them. In order to run a string of commands in a row, you have to keep typing them in. A string of commands in a row, which are saved in a file so that they can be run again and again is called a program . If you click on the “ new m-file ” icon, MATLAB opens up its built-in editor and you can write a program. MATLAB programs are always saved with the extension “m” (e.g. filename.m). MATLAB allows the user to build two types of programs. The first are called script files , and the second are called functions . They are both often referred to as m-files . Once you have written a program in the editor and saved it you can run it from the command window by simply typing its name without the .m . A script file is a simple sequence of MATLAB commands. A function is a script file which allows you to input variables. The first few lines of all m-files should be comment lines which describe what the program does, who wrote it, and the date it was last modified. Here is an example of a script file which is saved as
Background image of page 1

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

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

Page1 / 3

05 Writing Programs and Functions - 5 - Writing Programs...

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

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