SUNY Geneseo Department of Mathematics
Wednesday, April 26
Math 230 02
Spring 2017
Prof. Doug Baldwin
Monday, May 8, 8:00 AM.
Comprehensive, but emphasizing material since second hour exam (e.g., vectorization, strings, cell arrays, etc.).
Designed for around 1 1/2 hours, you’ll have 2 1/2.
Rules and format otherwise similar to hour exams, especially open-references rule.
I’ll bring donuts and cider.
2 completed so far (thank you to the two).
Sections 14.1 through 14.3
Suppose you wanted to make a list of pets, with each pet described by its name (a string), species (another string), and age (a number).
Relevant ideas or questions from reading:
variable = { data1_1, data1_2, ..., data1_n; data2_1, data2_2, ... data2_n; ... }
Solution:
>> pets = { 'Pet1', 'Dog', 2; 'Fido', 'Dog', 10 }
pets =
'Pet1' 'Dog' [ 2]
'Fido' 'Dog' [10]
Comments:
Now how would you pick information out of the pets cell array, e.g., the name of the second pet?
>> pets(2,1)
ans =
'Fido'
>> pets{2,1}
ans =
Fido
Notice the different ways Matlab displays the two results. The first with the indentation and quotation marks around strings indicates that what you’re seeing is a cell from a cell array. The second, unindented and without quotation marks, like strings normally display, indicates that what you’re seeing is the value in the cell.
To understand the difference between cells and values, think of cells as memory locations that tell the computer where to find values, possibly of different sizes than the values referenced by other cells. Normally, all values in an array must be the same size to allow indexing, but this idea of cells as fixed-size references to variable-size values allows Matlab to get around that restriction.
See handout for details.
Reading Matlab data from and writing it to files.
Read textbook section 4.12.