05 Writing Programs and Functions

05 Writing Programs and Functions - 5 Writing Programs and...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Functions - 1 5 - Writing Programs and Functions Writing MATLAB Programs When you type in commands at the >> prompt, you are using the MATLAB command window. Once the commands have been typed, you cannot easily go back and re-execute them. In order to run a string of commands in a row, you have to keep typing them in. A string of commands in a row, which are saved in a file so that they can be run again and again is called a program . If you click on the “ new m-file ” icon, MATLAB opens up its built-in editor and you can write a program. MATLAB programs are always saved with the extension “m” (e.g. filename.m). MATLAB allows the user to build two types of programs. The first are called script files , and the second are called functions . They are both often referred to as m-files . Once you have written a program in the editor and saved it you can run it from the command window by simply typing its name without the .m . A script file is a simple sequence of MATLAB commands. A function is a script file which allows you to input variables. The first few lines of all m-files should be comment lines which describe what the program does, who wrote it, and the date it was last modified.
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the 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