MATLAB FUNDAMENTALS HIGHER DIMENSION ARRAYS ADDITIONAL DATA TYPES

MATLAB FUNDAMENTALS: HIGHER DIMENSION ARRAYS ADDITIONAL DATA TYPES HP 100 – MATLAB Wednesday, 10/15/2014 www. clarkson. edu/class/honorsmatlab

Quotes "Your room should be a sacral temple for sleeping and love. " -Dr. Goss "Now you're a scared cat falling from a window. " -Prof Thomas "Directions are important; If the directions say 'do not stick your head in the snow blower' that's some good advice“ -Christopher Martin

Video: https: //www. youtube. com/watch? v=ee. U_Ib 8 Hs QM

Higher Dimension Arrays Vectors (1 x 5) 2 -D Matricies (5 x 5) Can also do 3 -D We can go much higher… Stretch into n dimensions k x = A(: , k) 1 -D 3 -D 2 -D

3 -D Arrays Most things in 2 -D extend to 3 -D! Defining Arrays: vectorized or in loops (if necessary) Indexing: (x, y) (x, y, z) (Rows, Columns, Depth) Functions: plot 3 Some work, some don’t vs. find

Additional Data Types So far, we have looked at: Numerical Arrays Logicals (aka Booleans) (0 or 1) There are more ways to store data in MATLAB! Character Arrays (Strings) Cell Arrays Structure Arrays

ADT: Character Arrays Character arrays just simply store characters, or strings in that good old fashioned English way. How we use them: >> dayofweek = input('Enter day of week', 's'); >> dayofweek = 'Wednesday'; Key Ideas: Each character is a sperate element in a character array dayofweek(4) n

ADT: Character Arrays 2 -D Character Arrays Require all Elements are the same length. N = [ ‘Jim'; ‘Joe'; 'Dr. Goss'; ]; Will not work! Use Instead: N = char( ‘Jim', ‘Joe', ‘Dr. Goss'); Don’t forget about converting numbers to strings!

ADT: Cell Arrays Cell arrays can store different types of data in their elements. So we can put some strings, some numbers, and some other things all together! How we make them:

ADT: Cell Arrays How We Make Them: >> days = {'Sunday', 1; 'Monday', 2; 'Tuesday', 3}; >> days = 'Sunday' [1] 'Monday' [2] 'Tuesday' [3] days is now a 3 x 2 Cell Array

ADT: Cell Arrays How We Use Them: To Squiggle or Not to Squiggle We can extract the elements from our Cell Arrays by using regular parentheses or squiggly brackets. Regular Parentheses: This will extract the entire cell, as a 1 x 1 cell. Squiggly Brackets: This will extract the data within the cell with its own data type.

ADT: Cell Arrays Continuing the cell array example from earlier… days{1, 1} days(1, 1) Sunday ‘Sunday’ days{1, 2} days(1, 2) 1 [1] So what’s the difference? One is inside a cell, and one is just the data!

ADT: Structure Arrays Structures are similar to cell arrays but they identify different types of data by fields. Example: N = {’Joe', ’Dr. Goss’, ‘Superman’}; Descrip = {‘MATLAB TA', ‘The Honors Program Director, . . . ’Superhero'}; whoswho(1). name = N{1}; whoswho(1). descrip = Descrip{1}; whoswho(2). name = N{2}; whoswho(2). descrip = Descrip{2}; whoswho(3). name = N{3}; whoswho(3). descrip = Descrip{3};

ADT: Structure Arrays >> whoswho = 1 x 3 struct array with fields: name descrip >> whoswho(2). descrip ans = The Honors Program Director

ADT: Overview We now have the following in our Arsenal: Numerical Arrays Character Arrays Logical Arrays Cell Arrays Structure Arrays The latter are used frequently in complex programming, especially when working with databases or just organizing large amounts of repetitive information to analyze.

Example Time Automobile Database Look on the Website for the format code

Questions? Comments? Concerns? Read Chapter 10 More on different types of arrays!

Homework! Nah… homework is lame. Instead…
- Slides: 18