MATLAB FINANCIAL DERIVATIVES TOOLBOX Instrukcja Użytkownika Strona 78

  • Pobierz
  • Dodaj do moich podręczników
  • Drukuj
  • Strona
    / 119
  • Spis treści
  • BOOKMARKI
  • Oceniono. / 5. Na podstawie oceny klientów
Przeglądanie stron 77
77
Fifth Section
5. m-files: Scripts and Functions
Up to this point, all commands passed to Matlab, were done through the
command window. But when a segment of programming code is composed
from several different commands, then it is time consuming, inefficient and
quite difficult to continue using the command window. To alleviate this
peculiarity, Matlab allows for the creation of functions and scripts by using
an Editor/Debugger that looks like a text editor.
As said, functions and scripts can be created with the use of the Matlab’s
Editor/Debugger. You only have to write the command lines, save the file in
a directory of your choice and execute it by typing its name to the command
window and pressing [Enter] (you have to make sure that the Matlab’s
current directory and the directory in which you save the file are the same).
Although m-files represent a text file and it is possible to use any text editor
to create a function or a script (as long as the extension of the file is *.m this
can work), it is preferable to use the default editor because: i) when you save
a file it automatically takes the extension *.m, ii) the reserved words like:
f
f
o
o
r
r,
w
w
h
h
i
i
l
l
e
e,
f
f
u
u
n
n
c
c
t
t
i
i
o
o
n
n,
e
e
n
n
d
d etc are blue colored whilst comments that make the
programming code more readable are green colored, and iii) it automatically
communicates with the command window and allows to run a script via a
command found in the Debug menu (see the menu bar of Editor/Debugger).
5.1 m-files: Functions
Functions are m-files that can accept input arguments and return output
arguments. The name of the m-file and of the
f
f
u
u
n
n
c
c
t
t
i
i
o
o
n
n should be the same.
Functions operate on variables within their own workspace, separate from
the workspace you access at the Matlab command prompt. Functions are
useful for extending the existing Matlab language for personal applications
For example a practitioner might want to write various functions that return
Przeglądanie stron 77
1 2 ... 73 74 75 76 77 78 79 80 81 82 83 ... 118 119

Komentarze do niniejszej Instrukcji

Brak uwag