Chapter 08

Chapter 08 - Chapter 8 Data Types Every modern programming...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Chapter 8 Data Types Every modern programming language provides means for storing numbers in variables, operating on them, and printing them. Matlab is no exception, and we have seen countless examples of numbers being stored, operated on, and printed. The examples suggest that these numbers are the same as the real numbers and complex numbers of mathematics, where there is no upper limit to absolute value of a number and no lower limit to the absolute difference between two numbers. On the other hand, since the space of mathematical numbers is infinite, while the memory of a computer is finite, it is clear that the use of a computer must impose some limits. It does. There is an upper limit to the size of a number on the computer, and there is a lower limit to the absolute difference between two numbers. The set of numbers that can be represented by a Matlab variable is, therefore, finite. We are about to learn that that there is more than one type of number in Matlab, and that each type provides a different set of allowed numbers. Furthermore, we will learn that there are types other than numeric types that hold other data. These other types cannot be used in arithmetic operations, but do allow other operations. A data type is in fact completely determined by the set of all possible values it can have and the set of operations that can be performed on it. Indeed, in the formalism of computer science, a data type , or simply, type , is defined as a set values and a set of operations that can be performed on those values. It is common to employ variables of several different types in a single function. It is even possible to use variables of different types in the same operations. Matlab does, however, enforce one rule of uniformity: All elements of a given array must be of the same type. We call the types of these elements elementary types . Thus, when we speak of the type of a variable that is not a scalar, it is not necessary to specify the type of each element in the array. We need specify only one elementary type. A complete description of the type of an array will include: the number of dimensions, the size in each dimension, and the type of the elements. In Matlab there are always two or more sizes because the number of dimensions is always 2 or more (even a scalar is a one by one matrix!) Example descriptions of types are • x is a 1 by 1 matrix with elements of type double • x is a scalar of type double • y is a row vector with 10 elements of type single • y is a 1 by 10 vector with elements of type single • A is a 2 by 3 matrix with elements of type int8 • B is a 2 by 3 by 4 by 5 array with elements of type logical The class function To determine the data type of a Matlab variable, use the function class . For example, >> x = 14 x = 14 >> class(x) ans = double (Matlab uses the name class and reserves the name type for a command that prints out the contents of an M-file.) Values have types, even when they are not stored in a variable. Thus,Values have types, even when they are not stored in a variable....
View Full Document

This note was uploaded on 04/08/2008 for the course CS 103 taught by Professor Fitzpatrick during the Spring '07 term at Vanderbilt.

Page1 / 37

Chapter 08 - Chapter 8 Data Types Every modern programming...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online