Assignment 03

# Assignment 03 - University of California Berkeley Fall...

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

University of California, Berkeley Department of Mechanical Engineering Fall Semester 2008 Instructors: M. Frenklach, R. Horowitz E7, Assignment 3 Assigned: Thursday, September 18, 2008 Due: 12:00pm, Friday, September 26, 2008. This assignment is an introduction to cell arrays and structure arrays. As before, turn in the hard copy of your published file to the drop boxes in Etcheverry 1109 and upload the soft copy of your script (the M-file) to bspace. Do not forget to name your M-file as lastname_firstname_SID_lab03.m MATLAB commands * introduced in this assignment: isequal, celldisp, cellplot, sortrows, mat2cell, str2double, mean, fieldnames 1. Create the cell array MyCell as follows: >> MyCell = {'Cal' 'Golden' 'Bears'} a) Run the following left-hand-side commands and explain, with a short sentence, what each of them does. (Right-hand-side commands may help.) >> t1= MyCell{2} >> class(t1) >> t2= MyCell(2) >> class(t2) >> t3= MyCell{2}(1) >> class(t3) >> t4= MyCell{end}(end) >> class(t4) >> t1 = MyCell(:) >> class(t1) >> MyCell{:} >> [t1,t2,t3] = MyCell{:} >> t1 = [MyCell(:)] >> isequal(t1,MyCell') >> t2 = {MyCell(:)'} >> isequal(t2{1},MyCell) >> t3 = [MyCell{:}] >> class(t4) >> t4 = {MyCell{:}} >> isequal(t4,MyCell) >> t1 = MyCell(2:3) >> size(t1) >> [t2,t3] = MyCell{2:3} >> class(t2) b) Write a single-line code that will produce 'Cal Golden Bears' from MyCell . * Please refer to MATLAB help to learn how to use the functions introduced in this assignment. Assignment 3 E7 1

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

View Full Document
University of California, Berkeley Department of Mechanical Engineering Fall Semester 2008 Instructors: M. Frenklach, R. Horowitz 2. Run the following commands to create the cell arrays A and B and compare them. >> A = {'Golden', {'Bears'}, [3,1;4,2]}; >> B = [{'Golden'}, {{'Bears'}}, {[3,1;4,2]}]; >> isequal(A,B) a) Run the following commands and explain what each of them does with a short sentence each. >> cellplot(A) >> size(A) >> Golden_rev = A{1}(end:-1:1) >> A{3}(:,1) = [10; 7]; b) Run the following three commands and explain what each does. >> A{2}(1) >> A{2}{1} >> A{2}{1}(1) c) Run the following commands and briefly comment on the results.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 6

Assignment 03 - University of California Berkeley Fall...

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

View Full Document
Ask a homework question - tutors are online