7_pdfsam_3 - example1.m . M-±les are text ±les and may be...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
3.3 Script M-Files For simple problems, entering commands at the Matlab prompt in the Command window is simple and efficient. However, when the number of commands increases, or you want to change the value of one or more variables, reevaluate a number of commands, typing at the Matlab becomes tedious. You will ±nd that for most uses of Matlab , you will want to prepare a script , which is a sequence of commands written to a ±le. Then, by simply typing the script ±le name at a Matlab prompt, each command in the script ±le is executed as if it were entered at the prompt. For more information, type help script . Script File: Group of Matlab commands placed in a text ±le with a text editor. Matlab can open and execute the commands exactly as if they were entered at the Matlab prompt. The term “script” indicates that Matlab reads from the “script” found in the ±le. Also called “M-±les,” as the ±lenames must end with the extension ‘.m’, e.g.
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: example1.m . M-±les are text ±les and may be created and modi±ed with any text editor. You need to know how to open, edit, and save a ±le with the text editor you are using. On a PC or Macintosh, an M-fle editor may be brought up by choosing New from the File menu in the Matlab Command window and selecting M-fle . The script M-±le is executed by choosing Run Script. .. from the File menu on a PC or Macintosh, or simply typing the name of the script ±le at the prompt in the Matlab command window. Example 3.2 Quadratic root fnding script Create the ±le named qroots.m in your present working directory using a text editor: % qroots: Quadratic root finding script format compact; a=1 b=5 c=6 x = -b/(2*a); y = sqrt(b^2-4*a*c)/(2*a); s1 = x+y s2 = x-y To execute the script M-±le, simply type the name of the script ±le qroots at the Matlab prompt: >> qroots a = 1 b = 5 c = 43...
View Full Document

This note was uploaded on 03/07/2010 for the course ENG 101 taught by Professor Chang during the Summer '09 term at 東京国際大学.

Ask a homework question - tutors are online