MATLAB FUNDAMENTALS.pptx - MATLAB FUNDAMENTALS Mark Jayson V Briones ECE,ECT VARIABLES Variables are fundamental to programming In a sense the art of

MATLAB FUNDAMENTALS.pptx - MATLAB FUNDAMENTALS Mark Jayson...

This preview shows page 1 - 10 out of 50 pages.

MATLAB FUNDAMENTALS Mark Jayson V. Briones, ECE,ECT
Image of page 1
Variables are fundamental to programming. In a sense, the art of programming is this: Getting the right values in the right variables at the right time A variable name must comply with the following two rules: ■ It may consist only of the letters a–z, the digits 0–9, and the underscore ( _ ). ■ It must start with a letter. VARIABLES
Image of page 2
The name may be as long as you like, but MATLAB only remembers the first 63 characters (to check this on your version, execute the command namelengthma x in the Command Window of the MATLAB desktop). Examples of valid variable names are r2d2 and pay_day . Examples of invalid names (why?) are pay-day , 2a , name$ , and _2a . VARIABLES
Image of page 3
A variable is created simply by assigning a value to it at the command line or in a program—for example, a = 98 If you attempt to refer to a nonexistent variable you will get the error message ??? Undefined function or variable ... The official MATLAB documentation refers to all variables as arrays , whether they are single-valued (scalars) or multi-valued (vectors or matrices). In other words, a scalar is a 1-by-1 array—an array with a single row and a single column which, of course, is an array of one item. VARIABLES
Image of page 4
MATLAB is case-sensitive , which means it distinguishes between upper- and lowercase letters. Thus, balance , BALANCE and BaLance are three different variables. Case Sensitivity
Image of page 5
Many programmers write variable names in lowercase except for the first letter of the second and subsequent words, if the name consists of more than one word run together. This style is known as camel caps , the uppercase letters looking like a camel’s humps (with a bit of imagination). Examples are camelCaps , milleniumBug , dayOfTheWeek . Some programmers prefer to separate words with underscores. Case Sensitivity
Image of page 6
Command and function names are also case-sensitive. However, note that when you use the command-line help, function names are given in capitals (e.g., CLC) solely to emphasize them. You must not use capitals when running functions and commands! Case Sensitivity
Image of page 7
Another fundamental concept in MATLAB is the workspace . Enter the command clear and then rerun the compound interest program. Now enter the command who . You should see a list of variables as follows: Your variables are: balance interest rate THE WORKSPACE
Image of page 8
All the variables you create during a session remain in the workspace until you clear them. You can use or change their values at any stage during the session.
Image of page 9
Image of page 10

You've reached the end of your free preview.

Want to read all 50 pages?

  • Fall '19
  • matlab, Vector Motors

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

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes