P. 1
Introduction to Matlab

Introduction to Matlab

|Views: 261|Likes:
Published by thesuperleo

More info:

Published by: thesuperleo on Sep 28, 2009
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

10/20/2011

pdf

text

original

These are subprograms stored in text files with .m extensions and are called M-files. A
function is different than a script in that the input parameters it needs are passed to it
with argument lists like Matlab commands (think about sin(x) or plot(x,y,’r-’)). Note,
however, that anything inside Matlab functions is invisible in the command window. So to
debug a function you need to use print and plot commands in the function file. Or you can
make it a stand-alone script by commenting out the function line so that its variables are
available at the Matlab command level.

You can also pass information in and out of functions by using Matlab’s global command
to declare certain variables to be visible in all Matlab routines in which the global command
appears. For instance, if you put the command

global a b c;

both in a script that calls derivs.m (see below) and in derivs.m itself, then if you give a,
b, and c values in the main script, they will also have these values inside derivs.m. This
construction will be especially useful when we use Matlab’s differential equation solving
routines in Chapter 16.

Rather than give you a syntax lecture I will just give you three useful functions as exam-
ples, with comments about how they work.

59

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->