5

Scripts and Functions

After studying this chapter, you should be able to:

  • write scripts and functions in MATLAB®
  • understand the scope of variables inside a function
  • represent and use polynomials

5.1 Introduction

MATLAB is a command-line driven language that sequentially processes whatever statements are entered at the command prompt. When working on large problems, it is convenient to save your code in a text file. MATLAB provides the facility to write a series of MATLAB statements in a file and then execute them with a single command. You can write your program in an ordinary text file, giving it a suitable name such as myfile.m. The program in myfile.m can be executed at the command prompt as follows:

  >> myfile %This would run the program ...

Get Programming in MATLAB ® now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.