1 / 11

Introduction to Programming in MATLAB

Introduction to Programming in MATLAB. Intro. MATLAB Peer Instruction Lecture Slides by  Dr. Cynthia Lee, UCSD  is licensed under a  Creative Commons Attribution- NonCommercial - ShareAlike 3.0 Unported License . Based on a work at  www.peerinstruction4cs.org.

tyne
Download Presentation

Introduction to Programming in MATLAB

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to Programming in MATLAB Intro. MATLAB Peer Instruction Lecture Slides by Dr. Cynthia Lee, UCSD is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.Based on a work at www.peerinstruction4cs.org.

  2. A number by any other name wouldn’t smell as sweet? Variable Names

  3. Which of these is NOT a legal variable name in MATLAB? • _factors_of_48_ • my_factors • factor • f • None or more than one of the above

  4. An important programming language concept called “scope” refers to the process for managing names, and how to resolve conflicts where different things have the same name. We’ll talk more about this later, but for now just something you should be aware of.

  5. Computer scientists call words/text/sentences/punctuation “strings” Strings in MATLAB

  6. Strings in MATLAB • Remember: to a computer, EVERYTHING is numbers • Numbers, letters, words, punctuation, images, video, sound • Even computer programs themselves! • In your lab, you got MATLAB to “reveal” to you its code numbers that it associates with each character in a string • ‘a’ = 97, ‘b’ = 98, … • This character code is a widely-used code called ASCII • Next slide gives part of the ASCII code (the whole thing goes from 0 to 255, next slide shows only 32 to 126)

  7. ASCII code (excerpt from 32 to 126)

  8. Which of the following is the result of running this code: >> foo = 'I can't wait to learn more about MATLAB!' + 1 • The value of the variable foo will be set to equal the string, and it will print foo = 'I can't wait to learn more about MATLAB!' • Several numbers will be printed (one for each character in the string) • MATLAB will give an error

  9. Text messages from inside the belly of the beast—just like real text messages with their LOLZ, BRB, IKWYM, IDK, TTYL, program errors require some clues to interpret. Interpreting MATLAB Errors

  10. Which of these shows the outcome when “factor(16+) + 3” is typed? >> factor(16+) + 3 ??? factor(16+) + 3 Error: Unbalanced or unexpected parenthesis or bracket. >> factor(16+) + 3 ??? factor(16+) + 3 | Error: Unbalanced or unexpected parenthesis or bracket. >> factor(16+) + 3 ??? factor(16+) + 3 | Error: Unbalanced or unexpected parenthesis or bracket. (a) (b) (c)

  11. What does the 24 refer to in this error message? >> factor(48.001) ??? Error using ==> factor at 24 N must be a nonnegative integer.  • It doesn’t refer to anything—just jibberish • 48.001 is the argument, and 2 * 24 is 48, so it’s a number you encounter when factoring 48 • It is a location in the code for the factor function • None or more than one of the above

More Related