Lab 07 - Problems-1

Lab 07 - Problems-1 - UNIVERSITY OF CALIFORNIA BERKELEY...

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

UNIVERSITY OF CALIFORNIA, BERKELEY Engineering 7 – Spring 2009 Department of Civil and Environmental Engineering Instructor: Professor Rector 1 Lab 07 [20 pts] Topics : Data Structures (Cell Arrays, Structure Arrays) Assigned : Monday, 03/16/2009 Due : Monday, 03/30/2009 Type : Take-home Remember to use the help command if you are not familiar with a command. It will be much faster than waiting for a GSI to answer your question. Moreover, a list of useful commands is provided at the end of this document. For this lab, you may submit your report as one Word document or one PDF file. If you submit a Word document, please do not use headers/footers. Remember to submit both a hard-copy and electronic copy of the report on BSpace Thanks! 0 Differentiating Data Types MatLab supports a variety of data (variable) types as you may have noticed, of which we have used the “double” data type the most frequently. In this lab, you will about the 3 other variable types known as strings, cells, structures. MatLab also has other types such as functions, objects, and even custom classes that can be defined by the user. 1. Examples of Data Structures 1.1 Character Arrays (1 pt) As you may know by now, Matlab supports arrays of characters. The following command establishes A as a 1x3 array of characters: >>A=’cat’ Character arrays can be manipulated with many of the commands that work on number arrays. To see this, enter the following commands: >> B=[A, ‘erpillar’] %concatenation >> C=B >> C(1:length(A))=’dog’ >> class(C) >> B == C >> strcmp(B,C) Copy each of the above commands and the corresponding outputs into your lab report. 1.2 Cell Arrays (2 pt) Cell arrays have the advantage that each element can contain any type of data. This is in contrast to the arrays we have dealt with so far, which have been restricted to containing only numbers. Being sure to use squiggly braces {} , create a cell array using the following command: >>A={54 ’cat’} In your lab report, explain the difference between the variables B and C created using the following commands: >>B=A(1) >>C=A{1}

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

View Full Document
Lab 07 2 UNIVERSITY OF CALIFORNIA, BERKELEY Engineering 7 – Spring 2008 Department of Civil and Environmental Engineering Instructor: Professor Rector Hint: check the class of each variable (use the command class ). Entering the commands below, note that a cell array can even contain a cell array as one of its elements: >>D={A ’dog’ B} where A and B are the variables created earlier. Copy the above command and its output into your lab report. Next, note that D{1}{2} extracts the 1x3 character array ’cat’ from the cell array D . Copy these two commands into your
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 5

Lab 07 - Problems-1 - UNIVERSITY OF CALIFORNIA BERKELEY...

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

View Full Document
Ask a homework question - tutors are online