Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
18
Добавлен:
09.02.2015
Размер:
195.07 Кб
Скачать

Is unspecified or is the empty string (''), matlab's default

encoding scheme is used.

For example,

fid = fopen('japanese_in.txt');

b = fread(fid,'*uint8')';

fclose(fid);

str = native2unicode(b,'Shift_JIS');

disp(str);

b = unicode2native(str,'Shift_JIS');

fid = fopen('japanese_out.txt','w');

fwrite(fid,b);

fclose(fid);

reads, displays, and writes some Japanese text. The disp(str)

command requires that str consist entirely of Unicode characters to

display correctly. The example calls FWRITE to save the text to a

file 'japanese_out.txt'. To write this file using the original

character set, call UNICODE2NATIVE first to convert the Unicode

string back to 'Shift_JIS'.

Here is an equivalent way to read, display, and write Japanese text,

again assuming that the computer is configured to display Japanese:

fid = fopen('japanese.txt', 'r', 'n', 'Shift_JIS');

str = fread(fid, '*char')';

fclose(fid);

disp(str);

fid = fopen('japanese_out.txt', 'w', 'n', 'Shift_JIS');

fwrite(fid, str, 'char');

fclose(fid);

See also native2unicode.

Reference page in Help browser

doc unicode2native

String to number conversion

<num2str> - Convert numbers to a string.

NUM2STR Convert numbers to a string.

T = NUM2STR(X) converts the matrix X into a string representation T

with about 4 digits and an exponent if required. This is useful for

labeling plots with the TITLE, XLABEL, YLABEL, and TEXT commands.

T = NUM2STR(X,N) converts the matrix X into a string representation

with a maximum N digits of precision. The default number of digits is

based on the magnitude of the elements of X.

T = NUM2STR(X,FORMAT) uses the format string FORMAT (see SPRINTF for

details).

If the input array is integer-valued, num2str returns the exact string

representation of that integer. The term integer-valued includes large

floating-point numbers that lose precision due to limitations of the

hardware.

Example 1:

num2str(randn(2,2),3) produces the string matrix

-0.433 0.125

-1.671 0.288

Example 2:

num2str(rand(2,3) * 9999, '%10.5e\n') produces the string matrix

8.14642e+003

1.26974e+003

6.32296e+003

9.05701e+003

9.13285e+003

9.75307e+002

See also int2str, sprintf, fprintf, mat2str.

Reference page in Help browser

doc num2str

<int2str> - Convert integer to string.

INT2STR Convert integer to string.

S = INT2STR(X) rounds the elements of the matrix X to integers and

converts the result into a string matrix.

Return NaN and Inf elements as strings 'NaN' and 'Inf', respectively.

See also num2str, sprintf, fprintf, mat2str.

Reference page in Help browser

doc int2str

<mat2str> - Convert a 2-D matrix to a string in MATLAB syntax.

MAT2STR Convert a 2-D matrix to a string in MATLAB syntax.

STR = MAT2STR(MAT) converts the 2-D matrix MAT to a MATLAB

string so that EVAL(STR) produces the original matrix (to

within 15 digits of precision). Non-scalar matrices are

converted to a string containing brackets [].

STR = MAT2STR(MAT,N) uses N digits of precision.

STR = MAT2STR(MAT, 'class') creates a string with the name of the class

of MAT included. This option ensures that the result of evaluating STR

will also contain the class information.

STR = MAT2STR(MAT, N, 'class') uses N digits of precision and includes

the class information.

Example

mat2str(magic(3)) produces the string '[8 1 6; 3 5 7; 4 9 2]'.

a = int8(magic(3))

mat2str(a,'class') produces the string

'int8([8 1 6; 3 5 7; 4 9 2])'.

See also num2str, int2str, sprintf, class, eval.

Overloaded methods:

gf/mat2str

Reference page in Help browser

doc mat2str

<str2double> - Convert string to double precision value.

STR2DOUBLE Convert string to double precision value.

X = STR2DOUBLE(S) converts the string S, which should be an

ASCII character representation of a real or complex scalar value,

to MATLAB's double representation. The string may contain digits,

a comma (thousands separator), a decimal point, a leading + or - sign,

an 'e' preceding a power of 10 scale factor, and an 'i' for

a complex unit.

If the string S does not represent a valid scalar value, STR2DOUBLE(S)

returns NaN.

X = STR2DOUBLE(C) converts the strings in the cell array of strings C

to double. The matrix X returned will be the same size as C. NaN will

be returned for any cell which is not a string representing a valid

scalar value. NaN will be returned for individual cells in C which are

cell arrays.

Examples

str2double('123.45e7')

str2double('123 + 45i')

str2double('3.14159')

str2double('2.7i - 3.14')

str2double({'2.71' '3.1415'})

str2double('1,200.34')

See also str2num, num2str, hex2num, char.

Overloaded methods:

opaque/str2double

Reference page in Help browser

doc str2double

<str2num> - Convert string matrix to numeric array.

STR2NUM Convert string matrix to numeric array.

X = STR2NUM(S) converts a character array representation of a matrix of

numbers to a numeric matrix. For example,

S = ['1 2' str2num(S) => [1 2;3 4]

'3 4']

The numbers in the string matrix S should be ASCII character

representations of a numeric values. Each number may contain digits,

a decimal point, a leading + or - sign, an 'e' or 'd' preceding a

power of 10 scale factor, and an 'i' or 'j' for a complex unit.

If the string S does not represent a valid number or matrix,

STR2NUM(S) returns the empty matrix. [X,OK]=STR2NUM(S) will

return OK=0 if the conversion failed.

CAUTION: STR2NUM uses EVAL to convert the input argument, so side

effects can occur if the string contains calls to functions. Use

STR2DOUBLE to avoid such side effects or when S contains a single

number.

Also spaces can be significant. For instance, str2num('1+2i') and

str2num('1 + 2i') produce x = 1+2i while str2num('1 +2i') produces

x = [1 2i]. These problems are also avoided when you use STR2DOUBLE.

See also str2double, num2str, hex2num, char.

Overloaded methods:

opaque/str2num

Reference page in Help browser

doc str2num

<sprintf> - Write formatted data to string.

SPRINTF Write formatted data to string.

STR = SPRINTF(FORMAT, A, ...) applies the FORMAT to all elements of

array A and any additional array arguments in column order, and returns

the results to string STR.

[STR, ERRMSG] = SPRINTF(FORMAT, A, ...) returns an error message when

the operation is unsuccessful. Otherwise, ERRMSG is empty.

SPRINTF is the same as FPRINTF except that it returns the data in a

MATLAB string rather than writing to a file.

FORMAT is a string that describes the format of the output fields, and

can include combinations of the following:

* Conversion specifications, which include a % character, a

conversion character (such as d, i, o, u, x, f, e, g, c, or s),

and optional flags, width, and precision fields. For more

details, type "doc sprintf" at the command prompt.

* Literal text to print.

* Escape characacters, including:

\b Backspace '' Single quotation mark

\f Form feed %% Percent character

\n New line \\ Backslash

\r Carriage return \xN Hexadecimal number N

\t Horizontal tab \N Octal number N%

where \n is a line termination character on all platforms.

Notes:

Соседние файлы в папке Библиотеки Matlab