1 / 13

CS 170 – Intro to Scientific and engineering Programming

CS 170 – Intro to Scientific and engineering Programming . Data types. So far we have seen the following data types: Double Char String Other?. The class function. What is a class? A  class  is the blueprint from which individual objects are created . Ex. >> x = 14 x = 14

eamon
Download Presentation

CS 170 – Intro to Scientific and engineering Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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 • findstrfinds the positions of a substring in a string (see also strfind) • ischarreturns 1 if argument is a character array and 0 otherwise • isletterfinds letters in string • isspacefinds spaces, newlines, and tabs in string • isstrpropfinds 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 • regexpfinds substrings defined by a regular expression • sprintfwrites formatted data to string (cf. fprintf) • strcatconcatenates strings • strmatchsearch array for rows that begin with specified string • strncmpapplies strcmp to the first n characters of strings • strcmpreturns 1 if two strings are equal and 0 otherwise • strcmpilike strcmp but independent of case • strncmpcompares first n characters of strings • strncmpilike strncmp but independent of case • str2num converts string to number • upper converts string to upper case

  13. Questions??

More Related