characters , strings , conversions
    (do examples on Matlab)
  • A string is a sequence of characters stored as an array of ASCII characters.
        Should be written within single quotes. Spaces are significant.

  • Examples:
    words = 'Hello World';   howRU = 'how are you';
    whos words   returns:   1×11 char
    words(1:4)   returns:   Hell
    new = [ words, ' - ', howRU]   returns:   Hello World - how are you

  • spell backwards:
    m = 'Oct';   try:   m+1 , can you guess what happens?
    rev = m(3:-1:1) = tcO  
    s = 'Knoxville'   length(s) = 9 ,   rev = s(9:-1:1) = ellivxonK  
    s'   rev'

  • conversions ASCII - decimal - binary - hexadecimal - char:
    double('@') = 64 ,   dec2bin(64) = 1000000 ,   dec2hex(64) = 40 ,   char(64) = @
    double('A') = 65 ,   dec2bin(65) = 1000001 ,   dec2hex(65) = 41 ,   char(65) = A

    dec2bin(126) = 1111110 ,  bin2dec('1111110') = 126 ,   dec2hex(126) = 7E ,   hex2dec('7E') = 126 ,   char(126) = ~

  • sprintf:
    s = sprintf( '...%...', ... ) creates a (formatted) string array, that can be displayed with disp(), or passed to a function, or be modified as a string.
      Can create indexed filenames like "file1.out" , "file2.out" , "file3.out":
        for i=1:3
            fname(i) = sprintf( 'file%d.out' , i )
        end