% IAP 2007 Introduction to MATLAB: Interface and Basics % Instructor: Violeta Ivanova, violeta@mit.edu % EXAMPLE 1 Massachusetts Census Data % Data import & export, variables, vectors, operators, built-in functions. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % A. DATA I/O % A1. Import census data using the Import Wizard % Load the numerical data from file MA2000census.dat into a matrix called N. % Hint: import only the numerical 14x9 matrix data after changing its name. % A2. Display the elements of the matrix N %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % B. VECTORS & MATRICES % B1. Create a vector Area of county areas from matrix N: % B2. Create vectors M and F with county populations by gender: % B3. Create a vector P with total county populations: % B4. Create a matrix G with county populations of both genders: males in one % column, and females in the second collumn. % From the matrix N: % From the two vectors M and F: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % C. MATRIX OPERATIONS % C1. Addition: From the vectors M and F, create a vector All with total number % of people in each county. % C2. Division: Create a column vector Ppa with population density (number of people % per area) for each county. Note: you must use the . operator! % C3. Create a 14x2 matrix Pct with percents of males (one column) and females % (another column) for each county. Note: you must use the . operator! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % D. VARIABLES % Test what variables have been created so far with functions WHO or WHOS: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % E. BUILT-IN FUNCTIONS % E1. Function SUM: Compute the total number MAall of residents in MA. % E2. Function MEAN and STD: Compute the mean and standard deviation % of the numbers of males and the numbers of females in MA counties. % E3. Function SAVE: Export the percentile matrix Pct to a text file. % E4. Function LOAD: Import the saved data from the file into a matrix Percents.