All programs are composed of two items: Data and Operations on that Data. Because, at their heart, computers are simple devices, they can only represent very simple pieces of information. All complex information must be built up from these basic Data Types. The data types can roughly be described as: numbers, booleans, characters, arrays, and structures. Some languages like ActionScript replace characters with "strings". Object oriented languages, such as C++ and Java replace "structures" with "objects".
All programs involve storing and manipulating data.
Luckily (???) the computer only knows about a few types of data. These include, numbers, true/false values, characters (a,b,c,1,2,3,etc), lists of data, and complex "Structures" of data, which build up new data types by combining the other data types.
Here is a brief summary of the available data types:
Numbers, (e.g., 7, 3.14).
Booleans (true or false)
Characters ('a', 'b', ... 'z', '1', '2', ... '9', '!', '^', etc)
Arrays (a list of data (all of the Same Data Type!))
Structures (a collection of named data referring to a single entity)
Numbers, (e.g., 7, 3.14)
Booleans (true or false)
Strings (a list of characters ("hello", "jim"))
Arrays (a list of data)
Objects (a collection of named data referring to a single entity (also contains functions on that data))
All computer programs, from brain scanners to video games to music players, use these same basic data types to represent all possible information.
It should be noted that computer programs often approximate information, that is they represent information inaccurately or perhaps it would be better to say imprecisely. An example of this is the value of pi. For most of us, pi is roughly 3.1415 and this value works just fine. For engineers pi is 3.14159265358979323846. For mathematicians and scientists, pi might be 3.1415926535897932384626433832795029. Thus it can be said that a computer deals in abstractions and approximations.
Below are some more examples and specifics for the various data types.
Numbers
students_listening = 112; % an "integer" (whole) number
average_number_of_students_in_class = 89.5; % a "double" (a real) number
Integers or Whole Numbers
(e.g., 0,1,2,3,123123, 12)
Advanced Concept: Unsigned Integers.
Real Numbers, called doubles or floats. These are numbers represented with a decimal point. (e.g., 1.1, 5.0, 3.1419, -1234234.01, 0.0000001)
Booleans (true or false)
utah_won_the_game = true;
Booleans were named after the famous Mathematician, George Boole
Booleans are good for knowing the status of something... I am learning vs. I am NOT learning.
Many math operations give us boolean answers, such as "not equal" (e.g., "5 ~= 10"), "less than" (e.g., 5 < 10), and "greater than" (e.g., 5 > 10)
Warning: The two Booleans values are true and false, (not the strings 'true' and 'false' but keywords true and false. Further, while some languages allow you to use 1 and 0 for true and false, every time you write a program and need to assign the value's true or false, you should use the keywords true and false, not the shortcut 1,0.
Characters ('a', 'b', ... 'z', '1', '2', ... '9', '!', '^', etc)
middle_initial = 'j';
Note: '1' is NOT 1. The character is NOT the numeric value!
Characters are usually not used by themselves, but in concert with many other characters (e.g. a book!). See below on arrays of characters!
Arrays (a lists of data (of the SAME TYPE!))
student_grades = [97, 78, 88, 93, 89];
Whenever you talk about an array, you should say, "an array of _WHAT_" (where WHAT is a DATA TYPE).
Several array examples:
student_grades = [97, 78, 88, 93, 89]; % an array of integers
student_name = ['j','i','m']; % an array of characters (aka a string)
student_name = 'jim'; % the same array of characters using a shortcut definition (same Semantics, different syntax!)
Note 1: I will use the term "string" to refer to an array of characters!
Note 2: Arrays are the foundation data type in Matlab.
While I will tend to make a distinction between variables that contain a single value and arrays (which almost always contain multiple values) in Matlab, you can treat all variables as if they are arrays (an array containing a single value is equivalent to a regular variable containing a number, and vice versa), thus:
age = 21; age = [21]; % technically the same
You can find more info on arrays under the chapter explicitly dealing with arrays.
Structures are a way to create more complex "Data Types" than the basics. They basically allow you to "build up" bigger and more interesting collections of data by naming sub-parts of information.
Below, we create a "student structure" containing, an integer part (the age), a string part (the name), and a boolean part (the fact that tuition has been paid or not).
student.name = 'jim'; % array of characters, or string, part
student.age = 27; % an integer part
student.paid_tuition = false; % a boolean part
For more information on Structures, please read the chapter devoted to the subject.