matlab_intro_1.doc

Upload: benazir-begam

Post on 04-Jun-2018

213 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/14/2019 Matlab_Intro_1.doc

    1/9

    Kings College London Sue Grimmond

    Introduction to Matlab1

    MATLABis a computer program by MathWorks, Inc. for people doing numerical computation.Matlab handles numerical calculations and high-uality graphics, pro!ides a con!enientinterface to built-in state-of-the-art subroutine libraries, and incorporates a high-le!el

    programming language.The purpose of this document is to introduce you to some of the basic capabilities of Matlab"hich you "ill find useful for a range of data analysis, plotting, or modelling applications. #ou"ill learn to "ork "ith Matlab by sol!ing a series of e$ercises to read, analyse and plot a !arietyof micrometeorological data.

    0. Getting started

    %or the purpose of this introduction, "e "ill assume that you "ill be using Matlab on a &'-Windo"s machine, although the appearance and functionality of Matlab is largely platformindependent.

    Begin by starting Matlab from the (tart menu. The command "indo" "ill appear, and this is"here you enter commands. Matlab is )command dri!en*, unlike +$cel and most otherWindo"s-based programs.

    In this document the symbol represents the Matlab prompt in the command "indo".'ommands follo"ing it indicate that you should type these in Matlab commands or responsesare printed in Bookman %ont. &ushing the +nter key causes the command to be e$ecuted.

    Matlab has e$tensi!e help resources, a!ailable under the /elp tab of the MATLAB "indo", ortype

    help topic.

    Hint0se the key to recall pre!ious commands, "hich you can then edit or re-e$ecute. Type a

    letter or part command follo"ed by the key, and the last instance of a matching command

    "ill be recalled.

    1. Basic input and display

    Matlab stands for MATri$ LABoratory, and "as originally "ritten to perform matri$ algebra 1. It is!ery efficient at doing this, as "ell as ha!ing the capabilities of any normal programminglanguage. In most instances, the data "e "ill be dealing "ith are simple matrices, either single!alues, or one- or t"o-dimensional arrays. An e$ample of a one dimensional array 2!ector3 is asingle ro" or a single column of !alues.

    Assign a value into Matlab as a variable

    fred456.7

    Matlab will reply withfred4

    56.7666

    Use a semi-colon to prevent the screen output (this is crucial when working with largedatasets!)

    %red451

    A row-array can be entered as (try these)

    ro"5485,1.7,59:,;,pi,%red< ro"145=56

    1This document draws heavily from Introduction to Matlab by Dr. Dave Campbell, University of ai!ato, "amilton, #ew $ealand% and Matlab

    &'(IC( by )rof. *abriel +atul, Du!e University, #C, U('. 'nd Introduction to Matlab by )rof "ans )eter (chmid who was at that time atIndiana University, I#, U('- 'ny errors in this document are mine.2see (ection , below.

    - 1 -

  • 8/14/2019 Matlab_Intro_1.doc

    2/9

    Kings College London Sue Grimmond

    ro":46=6.1=56 increment by 0 (i" no increment used# de"ault is $)

    %et a list o" variables currently in the workspace# and their si&e

    "hos >ame (i?e Bytes 'lass

    %red 5$5 @ double array ans 5$5 @ double array fred 5$5 @ double array ro"5 5$; @ double array ro"1 5$56 @6 double array ro": 5$; @ double array

    rand total is 17 elements using 166 bytes

    'ote that Matlab is case-sensitive# hence "red and red are di""erent variables

    ou can also use the "unctions

    si?e2ro"13 length2ro":3

    Use semi colons to indicate the end o" a row or to create a column array

    col54851:< table548,:,:, 7=@ C=51