lecture05

# lecture05 - CS107: Computing for Math and Science Click to...

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

CS107, Prof. Stenberg F10 1 Lecture 05 Click to edit Master subtitle style CS107: Computing for Math and Science Lecture 05: means-ends booleans ifs

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

View Full Document
CS107, Prof. Stenberg F10 2 Lecture 05 Pieces to Build With Sequences of numbers first:last or first:step:last Select characters from a string string(positions) Concatenate strings or vectors [string1 string2] Upper / lower case upper(string) lower(string) Find one string in another findstr(string1, string2)
CS107, Prof. Stenberg F10 3 Lecture 05 Ways to Use the Pieces To get words from a string findstr(‘ ‘, string) to find spaces places( n ) to select nth space +1 or -1 to get place before or after space 1 or length(string) to get 1st or last place (begin:end) to select word

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

View Full Document
CS107, Prof. Stenberg F10 4 Lecture 05 example function [word1 word2] = twoWord(line) spacePlaces = findstr(' ', line); word1=line(1:spacePlaces(1)-1); word2=line(spacePlaces(1)+1:length(line)) ; end
CS107, Prof. Stenberg F10 5 Lecture 05 Meaning of Errors Index out of bound A number in ( ) is larger than length of vector or string Number is too large or vector is too short A number in ( ) is less than 1

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

View Full Document
CS107, Prof. Stenberg F10 6 Lecture 05 Index exceeds matrix dimensions function [word1 word2] = twoWord(line) spacePlaces = findstr(' ', line); word1=line(1:spacePlaces(1)-1); word2=line(spacePlaces(1)+1:length(line) +1); end
CS107, Prof. Stenberg F10 7 Lecture 05 Index exceeds matrix dimensions. >> twoWord2(line) ??? Index exceeds matrix dimensions. Error in ==> twoWord2 at 4 word2=line(spacePlaces(1)+1:length(line) +1);

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

View Full Document
CS107, Prof. Stenberg F10 8 Lecture 05 Problem Solving Methods Means - Ends Find a piece you know how to do Do it. Use variables for data you don’t immediately see how to get Do what has to go before that piece Do what comes after that piece Solve these problems by using the same method
CS107, Prof. Stenberg F10 9 Lecture 05 Capitalize a Word Problem: Capitalize a word First character upper case Rest lower case

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

View Full Document
F10 10 Lecture 05 Capitalize a Word What do we know how to do? firstUpper = upper(firstChar) What has to be done before? Put first character of word into firstChar What has to be done after? Get rest of word in lower case
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 02/10/2011 for the course COMPUTER S 107 taught by Professor Imielinizki during the Spring '11 term at Rutgers.

### Page1 / 52

lecture05 - CS107: Computing for Math and Science Click to...

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

View Full Document
Ask a homework question - tutors are online