Title: MatLab
1MatLab Palm Chapter 2, Part 3 Cell Arrays,
Structure Arrays
- Class 7.1
- Chapter 2 Sections 6 7
2Announcements
- Departmental Presentations.(REQUIRED
ACTIVITY)10/12 700-900 p.m. See online
Schedule - You must turn in two, one-page critiques (LIMIT
EACH CRITIQUE TO ONE PAGE!), one for each
presentation that you attend. - Due Thursday, October 21, 2004.
3Presentation Make-Up
- If you have a legitimate conflict
- Go to your conflicting class.
- Write a critique of the lecture/lab following the
format below (two pages if course conflicts with
both sessions of presentations) . - On your cover sheet, give the course, section,
and time of your conflict. - Non-course-related conflicts REQUIRE instructor
approval.
4Critique format
- Introductory paragraph. Start with broad
statement. Become more specific with sentences
that define the engineering field you heard
about. End with the topic sentence for your
critique.
5Critique format, continued.
- Example Introduction
- Civil engineers design, build and maintain
our nations infrastructure. They take courses
in structures, water resources, geotechnical
engineering, construction management, and
environmental engineering. These courses prepare
them to work in large or small firms that are
both governmental or private. Although there are
specific areas that CE majors can focus in, many
students choose the General Track, which
requires them to take electives in each of the
major areas within civil engineering. Because of
its breadth, civil engineering is an interesting
field, and the presenters for the department were
very effective at communicating their enthusiasm
for this subject.
Broad
Specific with definition
TopicSentence
6Critique format, continued.
- Two to three supporting paragraphs. These
paragraphs flesh out your topic sentence. They
MUST contain - A transition from the previous paragraph
- A key sentence (may be part of transition)
- Supporting sentences
- A concluding sentence
7Critique format, continued.
- Example supporting paragraph
- Enthusiasm may be hard to define, but you
know it when you see it. For instance, the
geotechnical presenter had positive body language
and used many personal examples to explain the
topic. She talked clearly, in an animated voice,
using a lot of hand gestures. She also had
energy and showed by her facial expression that
she was happy to be there and to have the
opportunity to talk to our class. One example
that stood out in my mind was how geotechnical
engineers have to ensure that neighboring
buildings are not damaged when a new facility is
constructed. The picture of the subway pit right
next to a major high-rise hotel brought that
message home. Because of the active and
interesting presentation style, this presentation
kept my attention.
Transition
Key sentence
Supportingsentences
Conclusion
8Critique format, continued.
- Conclusion paragraph. Should summarize the body
of the critique and draw the important
conclusions. Should NOT state substantially new
material.
9Critique format, continued.
- Example conclusion paragraph
- Through these many techniques, the Department of
Civil Engineering made a strong presentation.
Each presenter showed excitement, both through
energy, inflection, and personal example, and
through a communicated, genuine desire to inform
us about their topic and to teach us. They were
courteous in the way they treated late-comers and
loud students, while not letting the presentation
get out of control. They were also knowledgeable
and able to answer questions. Hence, since this
presentation was well-prepared and effectively
delivered, I was encouraged that it was a
beneficial use of my time.
Transition
Summary of supporting paragraphs
Final conclusion
10Critique Style
- Each paragraph should be about the same length.
- Sentences should vary in length.
11Critique Details
- Details (see example)
- 8 ½ x 11 paper, 1.5 times line spacing.
- One-inch margins on all sides.
- Times New Roman font.
- 12pt, bold title (maximum of two lines)
- 11pt body paragraphs.
- Underline Topic sentence, each key sentence,
and your final conclusion sentence. - Turn in three pages stapled(1) cover sheet with
personal information, (2) critique 1, (3)
critique 2.
12Announcements, cont.
- Next Monday will be Case Studies, led by an
industry sponsor (e.g. Dell, IBM, Frito Lay,
Motorola, etc.) - We may have handouts on Thursday, but make sure
you arrive on time, and are courteous, attentive,
and ready to work.
13Team Exercise
- Budgetary estimateHow much will it cost each
firm to give the case studies next week? Here is
what we know - Each team will be on campus for one full day.
- Each team is two to four people.
- Case studies require (?) hours of extra
preparation by (?) numbers of workers. - Travel is from within Texas.
14Budgetary Estimate
These costs are paid by the companies as part of
their outreach/promotional budgets. This is
probably a LOW estimate.
15Team Exercise (Adapted from Palm Ch. 3, No. 10,
p. 178)
- An object thrown vertically with a speed v0
reaches a height h at time t where - Write a function to compute h given v0 and t. It
should allow t to be a vector. - Use the function to PLOT (refer to p. 25) h
versus t for t between 0 and 10 s and v0 50
m/s.
16Function file (velocity.m)
- function h velocity(v0, t)
-
- function h velocity(v0, t)
-
- This function computes the height h of an
object at the time t after it is - released. The initial speed of the object is
v0. - INPUTS
- v0 initial speed (m/s)
- t time after release (s)
- OUTPUTS
- h height (m)
-
- S. Socolofsky
- ENGR 111A 501-503
- October 12, 2004
- Define the acceleration of gravity
- g 9.81 m/s
17Solution
- gtgt v_init 50
- gtgt t 00.110
- gtgt h velocity(v_init, t)
- gtgt plot(t, h)
- gtgt xlabel('Time after release (s)')
- gtgt ylabel('Height above release (m)')
- gtgt title('Position of a vertically released
object') - gtgt grid on
18Lec. 7.1 Learning Objectives
- Understand the differences between vector,
matrix, and structure arrays. - Understand the definitions for structure, record,
and field. - Be able to create a structure array using at
least two different methods. - Be able to store, retrieve, and manipulate data
in the different fields of a structure array.
19Cell Arrays
- A Cell Array is an array where each index is also
an array. - Each index can be a different data type (i.e. you
can have letters in one index and numbers in
another). - Allows you to give one name to a set of data that
belong together.
20Cell Arrays, continued.
- You can create Cell Arrays in two ways.
- Cell Indexing e.g. A(1,1) Walden
- Content Indexing e.g. A1,1 Walden
- Note the functions in Table 2.6-1 (p. 112)
- celldisp() and cellplot() are useful commands.
21Cell Practice
- Type the following commands
- gtgt A 14, 0, 9, 2, 25, 68
- gtgt celldisp(A)
- gtgt cellplot(A)
- gtgt A1,3
- gtgt A(1,3)
- gtgt A(1,2)
- gtgt A1,2
- gtgt A1,2(1,2)
- gtgt A(1,2)(1,3) why it this an error?
- gtgt A1,2(1,3) why does this work?
22New Topic Structure Arrays
- A structure array is a collection of records.
- A record is a set of related fields where each
field may contain a different data type. - A field is an array of data that defines a
particular attribute of an object. - structure array employee record
employee(3) List of fields name, address,
date of employment, salary. - or
- The collection of fields comprise a record the
collections of records comprise a structure array.
233.7 Structure Arrays
- Structure Arrays are like data objects in other
languages. - Structure(record).Field1 vector
- Structure(record).Field2 string
- Structure(record).Field3 number
- Fields can be arrays, character strings or
numbers.
24Structure Arrays
- By definition Structures are multidimensional
MATLAB arrays with elements accessed by textual
field designators. - Examples
- Student.name Data Type Text
- Student(2).scores(3) Data Type Array of
numbers.
25Creating Structures
- Structures can be created dynamically by direct
assignment to individual fields. - array_name(index).field_name field_value
- An entire record (element of the array) can be
added with a single statement. - Clue(n) struct(field name 1,field-value-1,
field name 2, field-value-2, .) - When text values are entered for a field they
must be enclose in single quotes. - Note
- If there is only one record in a structure,
there is no index needed between the array name
and the field name. If more than one record
exist then the index value must me given.
26Sample of Direct Assignment
- Array names and fields can be created and
assigned dynamically. - Clue.who 'Prof Plum'
- Clue.where 'Study'
- Clue.what 'Candlestick'
- disp(Clue)
- who 'Prof Plum'
- where 'Study'
- what 'Candlestick'
27More Samples
- Even though no index was used in creating the
- first record in 'Clue', another set can be
appended - by using an index.
- Clue(2).who 'Ms. Scarlet'
- Clue(2).where 'Library'
- Clue(2).what 'Rope'
- disp(Clue(2))
- who 'Ms. Scarlet'
- where 'Library'
- what 'Rope'
28Adding Fields
- New fields can be added after structures
- have been created.
- Clue(2).turns 15 turns is a new field
- disp(Clue(2)) used 1st in record 2
- who 'Ms. Scarlet'
- where 'Library'
- what 'Rope'
- turns 15
29Adding Fields
- Adding new fields will cause a 'null' field in
the cells already defined. - disp(Clue(1))
- who 'Prof Plum'
- where 'Study'
- what 'Candlestick'
- turns turns was not defined originally
30The Array Function struct()
- All fields (a complete record) can be assigned
with one statement. All text values are
enclosed in quotes numerical data are not. - Clue(3) struct('who', 'Col Mustard', 'where',
'kitchen', 'what', 'revolver', 'turns', 22) - disp(Clue(3))
- who 'Col Mustard'
- where 'kitchen'
- what 'revolver'
- turns 22
31Using Array Functions
- What does this code segment do?
- Clue(1).turns 17
- avg_turnssum(Clue.turns)/length(Clue)
- disp(avg_turns)
- 18
32Using Array Functions
- Since Clue(1).turns is null, , we can
assign it a value. - Clue(1).turns 17
- Below, notice the lack of an index for Clue and
the square brackets around Clue.turn. This
combination returns a vector of 'turns' to the
MATLAB function, sum, which calculates the sum
of that vector. - The length function returns the number of
records in Clue. - Dividing the sum by the number of records gives
us the average - of the numbers stored in turns.
- avg_turns sum(Clue.turns)/length(Clue)
- Then we display our results, show 18 as the
average. - disp(avg_turns)
- 18
33Try This!
- Use MATLAB to create a structure similar to the
Clue Game Database in the examples. - Try these commands in MATLAB
- Clue.who Clue
- Clue.who Clue(3).turns
- Clue.who Clue.where
- char(Clue.who) Clue(2).who
- Notice the different ways that the same data are
presented. - See a list of structure related function in Table
2.7-1 on page 120 of the text.
34RAT 7.1
- Take out a piece of paper, write your name,
team, todays date and RAT 7.1. - A structure array called profs has a field named
college. How would you assign the value
Engineering to this field for record number 2? - You dont have to turn in your paper
- Answer gtgtprofs(2).college Engineering
35Assignment 7.1
- INDIVIDUAL ASSIGNMENT
- Due March 9, 2004
- Chapter 2 49, 51 (End of chapter problems)
- Test your understanding problems 2.7-1,2,3 (p.
123)