ࡱ> %` 0"bjbj"x"x 0@@@  $ RRR8,DD\Uchooobbbbbbb$dh%gTbRooooobRRc###oRRb#ob##N]RRb B}_ ,_0b%c0Uc\_$ygY!fyg`bygRbT#ooobb"XoooUcoooo\\\\\\fz0DRRRR m-files Defined: An m-file is a MATLAB program Why an m-file? Faster execution versus typing each command one-by-one Record of commands used to produce a result Can edit and/or modify Can share with others File Extension: MUST be .m i.e., psi.m MATLAB sees .m files as programs to be executed Types: script file function file Script m-file A MATLAB program that contains a set of MATLAB commands to be executed in the order listed. These files may contain any number of commands, including those that call functions (built-in or created). Execution: Type the name of the file without the .m extension at the prompt >> psi (not psi.m) This is the same as typing all the commands stored in the script file one by one The script uses variables already defined in the workspace. Results obtained from executing script files are left in the workspace. Function m-file Similar to a script m-file, but the variables are all local. They are subroutines that scripts can call instead of having to reenter a portion of code in a script. Advantages: Break your program into separate tasks (called modular programming) Write the code once, test it and use it several times Main program, which calls the function, is easier to read Keeps the interactive MATLAB workspace free of unnecessary variables; the variables are all local Disadvantages: Functions are harder to test because the local variables, which may be needed for debugging, are not passed to the interactive MATLAB workspace Increases the number of m-files to keep track of in your directory The first line of a function m-file have mandatory format this is how MATLAB can tell the difference between the two m-file types. Function definition line: defines inputs and outputs function [output variables] = function_name (input variables) Workspace or one line in your script m-file: >>[X,Y,Z]= compute_something(A,B,C) Function that is called: function[R,S,T]= compute_something(x,y,z) Functions use variables already defined in the workspace Only variables identified to be output from the function are stored in the workspace Additional variables defined in the function, but not designated as output, are NOT added to the workspace All other variables are deleted after the function is executed Creating m-files: Open MATLABs built in file editor Use the open folder icon to open an existing m-file Use the blank page icon to open a new (blank) m-file The text editor will highlight in different colors certain programming commands; this is especially helpful to the programmer! Save your work frequently recall the file extension MUST be .m! Rules: The names of m-files must begin with a letter and cannot be longer than 63 characters Do not use a period in the name except for the .m Avoid names that identify build in function names (i.e., cos, sin, etc) or predefined variables such as pi or other functions/variables you have created Never name a script and function files the same name. The m-file MUST be in the directory listed in the MATLAB path you are in otherwise MATLAB will never find it. Called functions must be in the same path as the script calling it Path (or current directory) is located along the top of the MATLAB window (below the file, edit, help etc) in Current Directory you can also change directories here using the browse button (the button to the right of your location). Writing a function: Define what the function will accomplish identify the steps Identify the input, output and local variables Write the lines of MATLAB code first as a script m-file (NOT a function) This is so you can test the script m-file in the interactive MATLAB workspace Testing the script m-file Define input variable with test values The input variable names for the test MUST match the names used in the script m-file because all the variables are in the interactive workspace Run the script m-file. The results, output and local variables, are computed and reside in the interactive workspace Check that the steps and equations executed as planned If the equations use array operations, use arrays as your test variables Choose a meaningful function name (the name of the m-file) Write the first line of the function m-file following the correct syntax: function [output variables] = function_name (input variables) Resave assigning the function filename to the file (function name = filename) Test your function m-file by calling it from the interactive workspace. For convenience, use test input variable names that are the same as the names in the function Document (comment) your function. Be sure to include units and type (scalar, array or matrix) for each variable. Comment on the use of the function, remind yourself of assumptions made, what it is meant to do etc. Trust me, you will not remember the details a week later. Calling a function from a script: Ensure the function name is the same as your filename and is in your current directory Input variable lengths and types are appropriate for the function Dont input arrays if the program was written for scalars Units of the input data match the units used in the function Input variables in the call statement are listed in the same order as in the function. The names do not have to match, but the type of data (temp, pressure, etc) MUST match what the function expects Output variables in the call statement are listed in the correct order The names do not have to match, but the type of data (temp, pressure, etc) MUST match what the function expects [streamfunction] = psi (u,v) This calls the function m-file psi.m with input variables u and v and output variable streamfunction Example: Script m-file % filename = lab4.m % J. Beattie 10 Jan 2009 % SO414 Lab 4 % % Purpose: Calculate relative humidity % % Variables: % tmpc = Temperature (C) % dwpc = Dew Point Temperature (C) % relh = Relative humidity % % Functions called: % rel_humidity.m %---------------------------------------------- % begin script (example purpose only) tmpc = [10 14 20; -1 5 -3]; dwpc = [9.6 8 5; 8 5.0 -1]; [relh] = rel_humidity (tmpc, dwpc); % note the format in which the function is called % output in [] % function name exactly as function is saved % input in () Function m-file function [streamf] = psi(ua,ub,va,vb) % J. Beattie 10 Jan 2009 % SO414 PBL Project % % Purpose: Calculate the streamfunction given mean and anomaly % horizontal winds % % Variables: % ua = anomaly east/west wind % ub = mean east/west wind % va = anomaly north/south wind % vb = mean north/south wind % ----------------------------- % begin function  Adapted from: Jordon, M. S. 2007: MR2020 Course Notes and Pratap, R. 2006: Getting Started with MATLAB 7: A quick introduction for scientists and engineers.      3A/ 4 P Q _ N U u v ~ b k z { # & ȶȕtbtSth?3hs\CJOJQJaJ"h?3h)'5CJOJQJ\aJh?3h)'CJOJQJaJ"h?3h)'6CJOJQJ]aJ"h?3hz]]5CJOJQJ\aJh?3hz]]CJOJQJaJ"h?3hz]]6CJOJQJ]aJh?3h9CJOJQJaJ)jh?3h90JCJOJQJUaJ%h?3hz]]5>*CJOJQJ\aJ  23By. / 6 B P Q _ ' ( 4 u  & F gd)' & F gd)' & Fgd)'gdz]] & Fgd)'!""u ` a b c d e f g h i j k { & ' 3 w I J Y  & F gds\gd)'gdz]] & F gd)' & F gd)'h^hgd)'& 1 J Y VfTy\a6\pଡ଼t`RBh?3hs\6CJOJQJaJheCJOJQJ^JaJ&h?3hs\6CJOJQJ]^JaJ,h?3hs\56CJOJQJ\]^JaJ h?3hs\CJOJQJ^JaJ h?3h)'CJOJQJ^JaJh?3h)'CJOJQJaJ"h?3h)'6CJOJQJ]aJ"h?3h)'5CJOJQJ\aJh?3h)'CJOJQJaJh?3h)'6CJOJQJaJY ,-&'TxyK+a & Fgds\gds\ & Fgds\ & Fgd)' & Fgds\ & Fgds\gd)' & F gds\Z[\c*m[\p&tE & Fgd7( & Fgd7( & Fgds\ & Fgds\ & Fgds\gds\ & Fgds\p %&:BHtMSMfg(j{),:<CERҝ҈v"h?3h@5CJOJQJ\aJ(h?3h7(56CJOJQJ\]aJh?3h7(6CJOJQJaJ%h?3hs\5>*CJOJQJ\aJ"h?3h7(6CJOJQJ]aJh?3h7(CJOJQJaJh?3hs\6CJOJQJaJh?3hs\CJOJQJaJ,<wMg)9I;<gd7( & Fgd7( & Fgd7(gds\8^8gd7( & Fgd7( & Fgds\ & Fgd7(<ESg "7Iy0 @ p ~  gdgd)'gd@gd7(RS"67:H/ 0 o p ~  !+!N!̾ݾݾ̭̟̟̾̾̾̾̾̾̾̾̾̾}̾&h?3h@5CJOJQJ\^JaJhoCJOJQJ^JaJhCJOJQJ^JaJ h@h)'CJOJQJ^JaJh@CJOJQJ^JaJ h@h@CJOJQJ^JaJ h@h7(CJOJQJ^JaJ"h?3h7(5CJOJQJ\aJ1 )!!K!i!!!!!!!""""""""gdz]]gdArAgd)'gd@N!O!R!Z!h!i!l!m!p!u!!!!!!!!!!!!!!!!!!!!""""""""""""""""ᱤ}yqyqyqyqyjh~Uh~hChoCJhChoCJOJQJhoCJOJQJ hChojhCho0JU h@h)'CJOJQJ^JaJhArACJOJQJ^JaJ h@hArACJOJQJ^JaJ h@h@CJOJQJ^JaJh@CJOJQJ^JaJ,"""""gd)'.:p9/ =!"#$% <@< NormalCJaJmH sH tH DA@D Default Paragraph FontRiR  Table Normal4 l4a (k(No List6@6 C Footnote Text@&@@ CFootnote ReferenceH*@ 23By./6BPQ_'(4u`abcdefghijk{&'3w!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 23By./6BPQ_'(4u`abcdefghijk{&'3wIJY,-&'TxyK + a   Z [ \ c * m [ \ p &tE<wMg)9I;<ESg "7Iy0@p~)<>Ki000 000 0 0 0 000 0 000 0 000000 00 04 0000000000000000 0 0 0 000 0 000 0 000000000 0 0 0000 0 0 000000 0 0 0 0 0 0  0 00 0 0 0 0  0 0G 0G 0G 0G 0G 0 0 0J 0 0 0 000 0 0 0S 0S 0 0  0 0 0 00000000000000000000000000000000000@0@000@0@00000000@000@0X00@0X00@0X00@0X00X00,. & pRN!"u Y < """8@0(  B S  ?y|_p  $ ' ,: :HMOkm06y|X\lw33333333333333 3A6Qvk{'3y \ b \ p tSg"p~)<KiI, |qJZ%Tp"p;?|I"_'̖,;0Ұsj1h|6vQdl="Z~_>QbHj\e/qM9/[Fx&[L^g5a7 qHzZFqz*57uܝ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. ^`hH. ^`hH. PLP^P`LhH.h^`OJQJo(hHh^`OJQJo(hHohpp^p`OJQJo(hHh@ @ ^@ `OJQJo(hHh^`OJQJo(hHoh^`OJQJo(hHh^`OJQJo(hHh^`OJQJo(hHohPP^P`OJQJo(hH^`OJQJo(hH^`OJQJ^Jo(hHopp^p`OJQJo(hH@ @ ^@ `OJQJo(hH^`OJQJ^Jo(hHo^`OJQJo(hH^`OJQJo(hH^`OJQJ^Jo(hHoPP^P`OJQJo(hH^`o(. ^`hH. pLp^p`LhH. @ @ ^@ `hH. ^`hH. L^`LhH. ^`hH. ^`hH. PLP^P`LhH. w&[h|6bHp"~_>ZFqJZ|Ig5a;0{9/[57ue/qM_'I, sj17 q' Hydl=                                                                                          )0                                                                                                  ?3)'7(ArAs\z]]ep@9E+H~o@ j<  @@UnknownGz Times New Roman5Symbol3& z Arial5& zaTahoma?5 : Courier New;Wingdings 1h{F{FF= / /4d 2QP.2 FunctionsJCB Useritsd`                Oh+'0  0 < H T`hpx Functions JCB User Normal.dotitsd7Microsoft Office Word@@k$@X0 }@X}G|VT$mV J&" WMFC KklUT#m EMFk U"   % Rp@"Tahoma5& zaTahomawUnw- !p50Pp[wPՅwP0PlN0Pdv% Rp@"TahomapP0%0pPP ?0$+<$i0<**5& zaTahomaP0p50`Pp[w(PՅwdP0dPlN0|Pdv% Rp@"Tahoma PxP30GG4 P+0GP,0G`PG^6pPkT05& zaTahoma  /Mp50`Pp[w(PՅwdP0dPlN0|Pdv% % %  Rp@ Tahoma|}|P#D# 80TP\PmwP||}|w@##@BPߕw!5& zaTahoma(!8w(!?0Ll 0)0P0PlN0Pdv% %  TTWEUU@@LPmEXTTFWmUU@@FLP-m(TlnW,UU@@nLXfiles#7.'% Ld,? !??% ( % !% TT-OLUU@@-LP1L " % TTMW~UU@@MLP ~2 TT4UU@@"LP 2Rp@"Tahoma5& zaTahoma? HĹ)0P0PlN0Pdv% %  % Tx45UU@@L\DefinedUU>0303% TT$4DUU@@$LP:D!TTE4vUU@@ELP v2Rp@Wingdings П L(P0<*<*^60P@̪0̪0d0, 0, PX0H , ̒0;Wingdigs?0 l˘)0TP0TPlN0lPdv% Rp@"ArialRGGGGbbRRPPPPRRKKbKHHHH,j00P@̪000P@̪03& z Arial!0?`tl˘)0PP0PPlN0hPdv%  % TTUU@@LP*% TTUU@@LP l% TdWUU@@LTAn m73MTTXxUU@@XLP-x!TyUU@@yLfile is a MATLAB program 0)0G66.763 23!0MTTUU@@LP 1!"  TTUU@@nLP 2 % T|UU@@L\Why an mS3.03MTTUU@@LP-!Tl`UU@@LXfile?0,% TTPUU@@PLP 1 % TT]UU@@KLP*% TT^UU@@KLP l% Th ]UU@@K/LFaster execution versus typing each command one 00)0!0.0*323.0!)3(.33300*3*2MM033220TT  ]UU@@ KLP- !TX  ]UU@@ KLPby3.TT + ]UU@@ KLP-+ !T`,  ]UU@@, KLTone]230TT  ]UU@@ KLP 2!"  % TThUU@@LP*% TTgUU@@LP l% TP^ UU@@+LRecord of commands used to produce a resultm90*2!32*2MM033)3)/313!233*00!0)3TT ^ UU@@ LP  1!"  % TT:UU@@(LP*% TT;UU@@(LP l% TD:UU@@(L|Can edit and/or modify 70303033#2!L23-TTEu:UU@@E(LP u1!"  % TTEUU@@LP*% TTDUU@@LP l% T;UU@@LxCan share with others703)30!0D3230!)TT;+UU@@LP +1!"  TTUU@@&" WMFC +kLP 2 % T"UU@@tLhFile Extension003.03)23% TXWUU@@tLP: TTXUU@@XtLP 1 % TTUU@@LP1*% TTUU@@LP l% TdUU@@LTMUSTRD:8% Td(UU@@LT be 30% TX)UU@@)LP.mX% TcUU@@ Lh i.e., psi.m 02)MTTdUU@@dLP 2!"  % TTcUU@@QLP*% TTdUU@@QLP l% T`9cUU@@QLTMATPG76T\8 cUU@@8Q-LLAB sees .m files as programs to be executed .75)00)M0)0(3!23!0M)230/.0*302TT  cUU@@ QLP 02!"  TTdUU@@LP 2 % TlA UU@@/ LXTypes 6.30(% TTA UU@@/ LP:.!TT.A UU@@/ LP 1 % TTK  UU@@ LP1*% TTJ  UU@@ LP l% TA  UU@@ Ldscript file )*!30TTA $ UU@@ LP 32!"  % TT  UU@@ LP*% TT  UU@@ LP l% T ] UU@@ Lhfunction file33*230TT^  UU@@^ LP 22!"  TT  UU@@{ LP 2%  T| m UU@@ L\Script m:1(:%WTTn  UU@@n LP-1(Td & UU@@ LTfile#7TT' ` UU@@' LP T: % T  Ij UU@@X NLA MATLAB program that contains a set of MATLAB commands to be executed in the 7G75.763 23!0M30*2303)0)02G75.66*2MM033)1300.0*203330 T@k Y UU@@ SLorder listed. These files may contain any number of commands, including those that 2!30!)03630)00)M0.*230303.33M30 2*2MM033)3*333332)030TpZk  UU@@Z LX call *0 T KG UU@@5 Llfunctions (built33*23)#33TTL lG UU@@L5 LP-!Tm G UU@@m5 Llin or created).T32!*!0/03#TT G UU@@5 LP 01 TTH  UU@@ LP 2 T $ UU@@ LdExecution: 4.0*322!TT $ UU@@ LP 31 % TT/  UU@@ LP1*% TT.  UU@@ LP l% T% 6 UU@@ LType the name of the file 6.303030M02300% Tx7% v UU@@7 L\withoutD323% Tf % r UU@@f L the .m extension at the prompt30M0-03)230303!2M2TTs%  UU@@s LP 1!"  % TT UU@@ LP Tp >UU@@ LX>> psiCC3)TT- EUU@@- LP sTTF qUU@@F LP ,% Tr 2UU@@r Ld(not psi.m) #323)M#TT3 cUU@@3 LP 1Rp@1Courier New П (P0<*<*^60P@̪0̪0d0)?5 : Courie New?<4)0TP0TPlN0lPdv%  % TTvUU@@^LPo7% TT EqUU@&" WMFC k@^LP _% TEpUU@@F^JLThis is the same as typing all the commands stored in the script file one 63))30)0M00).323030*2MM033()2 03330)*!30230!"  TpFqXUU@@FLXby one3.230TTYqUU@@YLP 1!"  % TTNUU@@<LP*% TTOUU@@<LP l% T, NUU@@<%LThe script uses variables already def630)*!33)0).0!030(0!003.30TD `NUU@@ <)Lined in the workspace. Results obtained 303330C2!.)30*090)3)220203!"  TNN UU@@6Lfrom executing script files are left in the workspace.!2M0.0*333)*!30)0!00330D2 .)30)0TTO N UU@@O LP 2!"  TT+UU@@LP 2 TT,UU@@LP 2 TTUU@@LP 2 TT wUU@@eLP 2 TTxUU@@LP 2 TTTUU@@BLP 2 TTUUU@@LP 2 TT1UU@@LP 2 TT2UU@@LP 2 TTUU@@LP 2 TT}UU@@kLP 2 % T~UU@@ L`Function m5;;1&9;XTT~UU@@LP-(Td~UU@@LTfile#7TT~UU@@LP : % T[UU@@ILxSimilar to a script m3M0!20)*!3MTT:[UU@@ILP-!T;[UU@@;IJLfile, but the variables are all local. They are subroutines that scripts 03330.0!030)0!002*0630-0!0)33!2320)30)*!3( T[UU@@Lcan  call instead of havi*03*03)003230.T[sUU@@ Ldng to reent331!003T t[ UU@@t#Ler a portion of code in a script. 0!032!232*23030)*!3TX [ UU@@ LP TT [ UU@@ LP 1 Rp @Times New Roman@̪0\3T<<m?000^60@̪0̪0d0ľ50koW$Gz Times ew Romanp50Pp[w8/b1)0T0TlN0ldv% !T<*UU@@(L T|*UU@@L\ " ' % Ldjnj!??% ( % TT*UU@@LP -Rp @Times New RomanA*0.a:pu",/ =!"#$% 0d0m6i0  0 Gz Times ew Romanp50p[w8/b1)00lN0dv% % Rp @"Arial (PR%0R%0hA(P#0j3& z Arial?, l 0)0@P0@PlN0XPdv%  % !% TTUU@@LP1"" % TT(UU@@LP % T)UU@@)LAdapted from: Jordon, M. S. 207./../-G*....E7/.TTUU@@LP0.TT UU@@LP7.T  UU@@  L`: MR2020 E=../& WMFC k.T  UU@@ LhCourse Notes a</.*.<..*/T$ UU@@ $Lnd Pratap, R. 2006: Getting Started ..7./.<../.A...7./.Rp @Times New Roman#1 0|ˮ0`1 0Gz Times ew Roman?0`c4)0P0PlN0Pdv%  % TU nUU@@]ALwith MATLAB 7: A quick introduction for scientists and engineers.<.E74.87.7./*+....*/..**..**....././.*% TTV z pUU@@V ]LP %% 666666666666666666666666666666666666 6 66 6  6 66 6  6 66 6  6 66 6  6 66 6 66666666666666666666  ."System-@"Tahoma-@"Tahoma-@"Tahoma---@ Tahoma--  2 S`mT 2 Sk-T2 Spfiles - @ !(T`--,- 2 N1T'- 2 S T 2 a` T@"Tahoma---2 n`Defined - 2 n:T 2 n T@Wingdings-@"Arial-- 2 {`T- 2 {e T-2 {sAn m 2 {-T12 {file is a MATLAB program    2 { T,' 2 ` T-2 `Why an m  2 -T2 file?n- 2  T- 2 `T- 2 e T-R2 s/Faster execution versus typing each command one  2 x-T2 |by 2 -T2 one 2  T,'- 2 `T- 2 e T-L2 s+Record of commands used to produce a result  2 a T,'- 2 `T- 2 e T-.2 sCan edit and/or modify   2  T,'- 2 `T- 2 e T-+2 sCan share with othersy 2  T,' 2 ` T- 2 `File Extension-2 :  2  T- 2 `T- 2 e T-2 sMUST -2  be -2 .m -2  i.e., psi.m   2  T,'- 2 `T- 2 e T-2 sMAT O2 -LAB sees .m files as programs to be executed    2 x T,' 2 ` T-2 `Typesn- 2 ~:T 2  T- 2 (`T- 2 (e T-2 (s script file 2 ( T,'- 2 6`T- 2 6e T-2 6s function file 2 6 T,' 2 C` T-2 P`Script m 2 P-T2 Pfile 2 P T-2 ^`NA MATLAB program that contains a set of MATLAB commands to be executed in the     2 k`Sorder listed. These files may contain any number of commands, including those that   2 k call #2 x`functions (built 2 x-T"2 xin or created). 2 x T 2 ` T2 ` Execution:  2  T- 2 sT- 2 x T-22 Type the name of the file  -2  withoutm -:2 2 the .m extension at the prompt   2  T,'- 2 s T2 >> psi  2  T 2  T&-2  (not psi.m)  2   T@1Courier New- - 2 oT- 2  T -z2 JThis is the same as typing all the commands stored in the script file one   ,'2 by one 2  T,'- 2 sT- 2 x T-C2 %The script uses variables already defI2 B)ined in the workspace. Results obtained  ,'\2 6from executing script files are left in the workspace.  2  T,' 2 ` T 2 ` T 2 ` T 2 ` T 2 &` T 2 3` T 2 @` T 2 N` T 2 [` T 2 h` T 2 v` T-2 ` Function m 2 -T2 file 2  T-+2 `Similar to a script m  2 -Tz2 Jfile, but the variables are all local. They are subroutines that scripts 22 `can call instead of havi2  ng to reent@2 #er a portion of code in a script. 2   2  T@Times New Roman- ,C2 `( 2  '- @ !`- - 2  T@Times New Roman- - @"Arial- - ,- 2 `1T'- 2 d T- 82 gAdapted from: Jordon, M. S. 20   2 0T 2 7T2  : MR2020   2 7Course Notes aA2 $nd Pratap, R. 2006: Getting Started @Times New Roman- - m2 `Awith MATLAB 7: A quick introduction for scientists and engineers. - 2  T-՜.+,0 hp  usna/ '  Functions Title  "#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~Root Entry Fp}1Table!gWordDocument0@SummaryInformation(U4DocumentSummaryInformation8CompObjq  FMicrosoft Office Word Document MSWordDocWord.Document.89q