- publishing free software manuals
GNU Octave Manual
by John W. Eaton
Paperback (6"x9"), 324 pages, 4 figures
ISBN 0954161726
RRP £19.99 ($29.99)

Get a printed copy>>>

5.1 Creating Strings

Function File: blanks (n)
Return a string of n blanks.

Function File: int2str (n)
Function File: num2str (x)
Convert a number to a string. These functions are not very flexible, but are provided for compatibility with MATLAB. For better control over the results, use sprintf (see section 13.2.4 Formatted Output).

Built-in Function: setstr (x)
Convert a matrix to a string. Each element of the matrix is converted to the corresponding ASCII character. For example,

setstr ([97, 98, 99])
     => "abc"

Function File: strcat (s1, s2, ...)
Return a string containing all the arguments concatenated. For example,

s = [ "ab"; "cde" ];
strcat (s, s, s)
     => "ab ab ab "
        "cdecdecde"

Built-in Variable: string_fill_char
The value of this variable is used to pad all strings in a string matrix to the same length. It should be a single character. The default value is " " (a single space). For example,

string_fill_char = "X";
[ "these"; "are"; "strings" ]
     => "theseXX"
        "areXXXX"
        "strings"

Function File: str2mat (s_1, ..., s_n)
Return a matrix containing the strings s_1, ..., s_n as its rows. Each string is padded with blanks in order to form a valid matrix.

Note: This function is modelled after MATLAB. In Octave, you can create a matrix of strings by [s_1; ...; s_n] even if the strings are not all the same length.

Built-in Function: isstr (a)
Return 1 if a is a string. Otherwise, return 0.

ISBN 0954161726GNU Octave ManualSee the print edition