matlab代写

1

2

Lab 05 (Due: Sunday, October 7, 2018, 11 : 59 : 00pm Central Time)

CSCE 155N

Lab Objectives

􏰄 Write simple cell arrays
􏰄 Sting manipulations
􏰄 Understand how structures can be used to represent complex information 􏰄 Perform basic operations on structures

Prior to Laboratory

􏰅 Review the laboratory handout
􏰅 Read Chapter 7 strings and Chapter 8 in Attaway

3 Activities/Exercises Before You Begin

􏰅 Download the files from http://cse.unl.edu/ ̃cse155n/labs/05 to your Z:\csce155nm di- rectory

3.1 increasingStrings

  • 􏰅  Modify increasingStrings.m so that the function returns a cell array of three (3) strings

    where the first string has length 2, the second has length 3, and the third has length 4

  • 􏰅  The provided function randString will generate a string with a length between 0 and 6 (inclusive)
  • 􏰅  If randString returns a string of a length that is already in the cell array, keep the string that is already in the cell array

    3.1.1 Example

    >> increasingStrings
    ans =
    
'vp'    'hkn'    'IGZx'

1

3.2 randomSentence

  • 􏰄  Modify randomSentence.m so that the function returns words that can form a random sen-

    tence that is generated from banks of names, verbs, and nouns

  • 􏰄  The banks will be stored as cell arrays of strings
  • 􏰄  You create the words that will be used

3.2.1 Example

>> for i = 1 : 5
randomSentence
end
ans =
    'Stewart'    'milks'
ans =
    'Patrick'    'rides'
ans =
    'Patrick'    'herds'
ans =
    'Stewart'    'rides'
ans =
    'Ryan'    'herds'

‘bicycles’

‘cows’

‘sheep’

‘bicycles’

‘bicycles’

3.3 printRecord

  • 􏰅  Modify printRecord.m so that the function returns a string that displays information about

    the record

  • 􏰅  The record will be provided as a cell array
  • 􏰅  Use sprintf

Page 2

3.3.1 Example

>> record = { 0 , 'Ryan' , 43 }
record =
    [0]    'Ryan'    [43]
>> printRecord( record )
ans =
Ryan (ID: 0): 43 points

3.4 printInfo
􏰅 Modify printInfo.m so that the function returns a cell array of strings that reports the

names, heights, and final weights of the provided experiment subjects 􏰅 The subjects’ information will be provided in an array of structures 􏰅 Use sprintf

3.4.1 Example

>> subjects.name = 'Ryan';
subjects.id = 0;
subjects.weight = [ 134 145 ];
subjects.height.feet = 6;
subjects.height.inches = 0;
for s = 2 : 4
subjects( s ).name = char( randi( 26 , 1 , randi( 10 ) ) + 96 );
subjects( s ).id = randi( 100 );
subjects( s ).weight = randi( 100 , 1 , 2 ) + 100;
subjects( s ).height.feet = randi( 4 ) + 3;
subjects( s ).height.inches = randi( 12 ) - 1;
end
>> printInfo( subjects );
>> ans'

ans =

    'Ryan: 6'0", 145 pounds'
    'l: 4'5", 180 pounds'
    'qsthr: 5'11", 112 pounds'
    'pftg: 7'6", 190 pounds'

Page 3

4 webgrader and diffs

The webgrader contains a driver program which will test your programs and supply random inputs (and handle the output).

The diff program is being used to check for the correctness of your programs. If nothing appears in the diff section of the resulting pdf report, that means your program produced the correct for the given input.

You must run the webgrader at least once before 11 : 59 : 00pm on due date. 4.1 Members form

Each member must submit this file. You must submit this file if you want to run the webgrader.

  • 􏰅  Go to http://cse.unl.edu/ ̃cse155n/members
  • 􏰅  Select lab from the Assignment menu.
  • 􏰅  Select 05 from the Number (lab) menu.
  • 􏰅  Select your name from the User name.
  • 􏰅  If you are working in groups, then select your partner’s name from the menu.
  • 􏰅  Click Submit.

    4.2 Contributions form
    Each group member must submit this file individually.

  • 􏰅  Go to http://cse.unl.edu/ ̃cse155n/contributions
  • 􏰅  Select lab from the Assignment menu.
  • 􏰅  Select 05 from the Number (lab) menu.
  • 􏰅  Select your name from the User name.
  • 􏰅  If you are working in groups, then select your partner’s name from the menu and the fill the contributions form.
  • 􏰅  Click Submit.

    4.3 Web handin
    Only one member from each group must submit this.

  • 􏰅  Go to http://cse.unl.edu/handin
  • 􏰅  Enter your cse.unl.edu Username.
  • 􏰅  Enter your cse.unl.edu Password.
  • 􏰅  Select Lab05 from Assignments.
  • 􏰅  Choose to upload (4) files (randomSentence .m,increasingStrings.m, printRecord.m, printInfo.m).

Page 4

4.4 Web Grader
􏰅 Go to http://cse.unl.edu/ ̃cse155n/grade
􏰅 Enter your cse.unl.edu Username and Password. 􏰅 Select Lab05 from the Assignment Dropdown Menu. 􏰅 Click Grade Me!
􏰅 Click the generated link.
􏰅 Enter your cse.unl.edu Username and Password. 􏰅 Confirm the information in the resulting PDF.

5

Code Documentation

Remember to document your files in the way that we did for the previous labs. It will come in handy when you look back at code after a long time, or when someone else is trying to understand what your code does.

6 Topics Covered in Lab

􏰅 Input and output arguments as cell arrays 􏰅 Cell arrays
􏰅 Structures

7 What to Submit

You will be submitting six (6) files (increasingStrings.m, randomSentence.m, printRecord.m, contributions06lab.txt, members06lab.txt, and, printInfo.m).

8 Additional Resources

Online MATLAB Documentation CSE Webhandin
CSE webgrader

Page 5

9 Point Allocation

Component

Points

increasingStrings.m randomSentence.m printRecord.m printInfo.m members06lab.txt contributions06lab.txt webgrader PDF

20 20 20 20

5

5 10

Total

100

Page 6