{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

Info icon This 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 find that for most uses of Matlab , you will want to prepare a script , which is a sequence of commands written to a file. Then, by simply typing the script file name at a Matlab prompt, each command in the script file 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 file 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 file. Also called “M-files,” as the filenames must end with the extension ‘.m’, e.g.
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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern