images

2.1    String basics

2.2    Using the disp command to print a variable’s value

2.3    Getting information from the user

2.4    Vectors

2.5    Operations on vectors

2.6    Special vector functions

2.7    Using rand and randi

Most people are familiar with manipulating numbers from experience with calculators. Computers, however, can deal with many types of data besides individual numbers.

Groups of character symbols, which can form words, names, etc., are stored in MATLAB variables called “strings.” It turns out to be surprisingly important to manipulate strings as well as numbers. What sort of operations do you want to perform on strings? Strings can be combined together by concatenation (‘chaining together’). Substrings can be extracted by using indexing to refer to just part of a string. Sometimes you may want the string (e.g., ‘1.34’) that corresponds to a number (1.34), and sometimes you may want the number that corresponds to a string. A common motif is to concatenate strings representing words (e.g., 'The answer is ') and numbers (e.g., '3.44'), and display the result in the Command window with the disp command.

The input command enables the program to get information, either strings or numbers, from the user. Following a prompt, the user types the information into the Command window. This will enable construction of programs that interact with the user. Part II will describe ...

Get Learning to Program with MATLAB: Building GUI Tools now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.