02.03.2016 Views

MATLAB by rudra pratap

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Programming<br />

•<br />

'tn MA T LAB:<br />

Scripts and<br />

• Functions<br />

A distinguishing feature of <strong>MATLAB</strong> is its ease of extendability through userwritten<br />

programs. <strong>MATLAB</strong> provides its own language, which incorporates many<br />

features from C. In some regards, it is a higher-level language than most common<br />

programming languages, such as Pascal, Fortran, and C, meaning that you<br />

will spend less time worrying about formalisms and syntax. For the most part,<br />

<strong>MATLAB</strong>'s language feels somewhat natural.<br />

In <strong>MATLAB</strong> you write your programs in M-files. M-files are ordinary ASCII<br />

text files written in <strong>MATLAB</strong>'s language. They are called M-files because they must<br />

have a .m at the end of their name (like myfu nction.m). M-files can be created<br />

using any editor or word processing application.<br />

There are two types of M-files-script files and function files. We will now<br />

discuss their purpose and syntax.<br />

4.1 Script Files<br />

A script file is an M-file with a set of valid <strong>MATLAB</strong> commands in it. A script file is<br />

executed <strong>by</strong> typing the name of the file (without the .m extension) on the command<br />

line. It is equivalent to typing all the commands stored in the script file, one <strong>by</strong><br />

one, at the <strong>MATLAB</strong> prompt. Naturally, script files work on global variables, that<br />

is, variables currently present in the workspace. Results obtained from executing<br />

script files are left in the workspace.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!