Beruflich Dokumente
Kultur Dokumente
Suman Senden
rd
M.Sc. Engineering Geology, 3 Semester
Roll Number:08/2075
A script file contains multiple sequential lines of MATLAB commands and function calls. You can run a script by typing
its name at the command line.
To create scripts files, we need to use a text editor. We can open the MATLAB editor in two ways −
If we are using the command prompt, type edit in the command prompt. This will open the editor. You
can directly type edit and then the filename (with .m extension)
•Matlab function files are very similar to Matlab script files, with a few important
differences.
•Both are plain ASCII( American Standard Code for Information Interchange) files
containing Matlab commands, with ".m" file extensions.
•Ordinary script files have the problem that they run in the scope of the command
window. Any variables created get added to the workspace, and may replace other
variables that were already defined there with the same names.
•Variables defined and used in a function do not affect the regular Matlab workspace.
•As a consequence, functions have mechanisms for passing arguments into the
functions, and for returning the results.
Syntax
The general syntax of a Matlab function is as follows:
function [ outarg1, outarg2, ..., outargN ] = functionName( inarg1, inarg2, ..., inargM )
Recap
Script M-files =Text file containing MATLAB commends
Can save, share, edit M-files.
The name of the function file must be the name of the
function i.e. function myfile_name