Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING.

Similar presentations


Presentation on theme: "CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING."— Presentation transcript:

1 CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING

2 Data types So far we have seen the following data types: Double Char String Other?

3 The class function What is a class? A class is the blueprint from which individual objects are created. Ex. >> x = 14 x = 14 >> class(x) ans = double

4 Numbers

5 What’s the min? What’s the max? >> intmax('int32') ans = 2147483647 >> intmin('int32') ans = -2147483648 >> realmax('single') ans = 3.4028e+038 >> realmin('single') ans = 1.1755e-038

6 Changing types From int to double>> y = x y = 10 >> class(y) ans = Int8 >> y = double(y) y = 10 >> class(y) ans = double

7 More changes >> int8(9.4) ans = 9 >> int8(-9.4) ans = -9 >> int8(-9.5) ans = -10 >> int8(128) ans = 127 >> int8(-1000) ans = -128

8 Ascii characters

9 Strings and functions >> book_title = 'Matlab for Smarties‘ >> length(book_title) >> book_title(1) >> book_title(4:16) >> double(book_title) >> s = 'Two is company, three a crowd.'; >> ssub = s(13:end) >> a = 'Three, two, one'; b = ', '; c = 'BLASTOFF!'; >> count_down = [a,b,c]

10 More string functions >> x = pi; >> fprintf('x:\nto three decimal places: %6.3f\n', x); x: to three decimal places: 3.142 >> s=sprintf('x:\nto three decimal places: %6.3f\n', x); >> s

11 Even more… functions char converts type to char findstr finds the positions of a substring in a string (see also strfind) ischar returns 1 if argument is a character array and 0 otherwise isletter finds letters in string isspace finds spaces, newlines, and tabs in string isstrprop finds characters of specified type in string num2str converts number to string length determines the number of characters in string lower converts letters in string to lower case

12 Even more… functions regexp finds substrings defined by a regular expression sprintf writes formatted data to string (cf. fprintf) strcat concatenates strings strmatch search array for rows that begin with specified string strncmp applies strcmp to the first n characters of strings strcmp returns 1 if two strings are equal and 0 otherwise strcmpi like strcmp but independent of case strncmp compares first n characters of strings strncmpi like strncmp but independent of case str2num converts string to number upper converts string to upper case

13 QUESTIONS??


Download ppt "CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING."

Similar presentations


Ads by Google