O'Reilly logo

Programming in MATLAB ® by Ram N. Patel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required