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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.