scripts n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Scripts PowerPoint Presentation
Download Presentation
Scripts

Loading in 2 Seconds...

play fullscreen
1 / 10

Scripts

2 Views Download Presentation
Download Presentation

Scripts

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Scripts

  2. Scripts (m-file) Typing everything in the command window is inefficient Put all the commands/calculations we want to run in a script or ‘m-file’ instead. Allows us to: • Edit the commands • Save the commands • Run them all at once • Print out the list of commands on paper Script = ‘m-file’ = PROGRAM!

  3. Opening a New Script (m-file)

  4. Scripting Now we can type the lines of code: Notice that nothing happens yet – you’re just typing away

  5. Running Scripts Click ‘Run’ once you have all your commands entered • Command saves AND THEN runs

  6. Saving Scripts When you click ‘run’, MATLAB prompts you to name and save your m-file in your working directory: Good Practice: Pick a ‘good’ filename. Don’t pick untitled7.m

  7. File Naming Practices MATLAB names must start with a letter and contain only letters, numbers or underscores

  8. Running Scripts After you name the file, MATLAB tries to the run the script If all correct: • File name and all of the “ans = “ stuff prints in the command window • Text will appear in the Day1_Ex1.txt file (That’s where we told MATLAB to put the text)

  9. Presence of Errors If mistakes are present • MATLAB ‘dings’ at you • Red words appear in the command window • READ THE WORDS.Tells you what line number has the mistake • Fix mistakes the script • Click run again (changes are saved before script is executed) • Rinse and repeat until all mistakes are repeated • Can be helpful to clear the command window to see the new mistakes clearly

  10. Clearing the Command Window If the command window gets cluttered • Right-click in the command window and choose “clear command window” OR • Type ‘clc’ in command window OR • Insert ‘clc’ as the first line in your script • This will clear the window with every run