Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Одиноков / МиИПиС_асп_13г / MATLAB_R2013a_Выбор.doc
Скачиваний:
30
Добавлен:
15.04.2015
Размер:
4.03 Mб
Скачать

Floating-Point Functions

See Floating-Point Functions (R2013a>MATLAB>Language Fundamentals>Data Types>Numeric Types>Function Summary) for a list of functions most commonly used with floating-point numbers in MATLAB.

References

The following references provide more information about floating-point arithmetic.

References

[1] Moler, Cleve, "Floating Points," MATLAB News and Notes, Fall, 1996. A PDF version is available on the MathWorks Web site at http://www.mathworks.com/company/newsletters/news_notes/pdf/Fall96Cleve.pdf

[2] Moler, Cleve, Numerical Computing with MATLAB, S.I.A.M. A PDF version is available on the MathWorks Web site at http://www.mathworks.com/moler/.

  • R2013a>MATLAB>Language Fundamentals>Data Types>Characters and Strings>Create and Concatenate Strings

  • Creating Character Arrays

On this page…

Creating a Character String

Creating a Rectangular Character Array

Identifying Characters in a String

Working with Space Characters

Expanding Character Arrays

Creating a Character String

Create a string by enclosing a sequence of letters in single quotation marks, such as

myString = 'Hello, world';

If the text contains a single quotation mark, include two quotation marks within the string definition:

otherString = 'You''re right'; % Ответ: otherString = You're right.

In the MATLAB® computing environment, all variables are arrays, and strings are of type char (character arrays).

whos myString

Name Size Bytes Class Attributes

myString 1x12 24 char

Functions such as uint16 convert characters to their numeric codes:

str_numeric = uint16('Hello') % В оригинале - str_numeric = uint16(str).

str_numeric =

72 101 108 108 111

The char function converts the integer vector back to characters:

str_alpha = char([72 101 108 108 111])

str_alpha =

Hello

Creating a Rectangular Character Array

You can join two or more strings together to create a new character array. This is called concatenation and is explained for numeric arrays in the section Concatenating Matrices (R2013a>MATLAB>Language Fundamentals>Matrices and Arrays>Array Creation and Concatenation>Creating and Concatenating Matrices). As with numeric arrays, you can combine character arrays vertically or horizontally to create a new character array.

Alternatively, combine strings into a cell array (R2013a>MATLAB>Language Fundamentals>Data Types>Characters and Strings>Create and Concatenate Strings). Cell arrays are flexible containers that allow you to easily combine strings of varying length.

Combining Strings Vertically

To combine strings into a two-dimensional character array, use either of these methods:

  • Apply the MATLAB concatenation operator, []. Separate each row with a semicolon (;). Each row must contain the same number of characters. For example, combine three strings of equal length:

dev_title = ['Thomas R. Lee'; ...

'Sr. Developer'; ...

'SFTware Corp.'] % Ниже дается ответ как дополнение к оригиналу:

dev_title =

Thomas R. Lee

Sr. Developer

SFTware Corp.

If the strings have different lengths, pad with space characters as needed. For example:

mgr_title = ['Harold A. Jorgensen '; ...

'Assistant Project Manager'; ...

'SFTware Corp. '] % Ниже дается ответ как дополнение к оригиналу:

mgr_title =

Harold A. Jorgensen

Assistant Project Manager

SFTware Corp.

  • Call the char function. If the strings are different length, char pads the shorter strings with trailing blanks so that each row has the same number of characters. For example, combine three strings of different lengths:

mgr_title = char('Harold A. Jorgensen', ...

'Assistant Project Manager', 'SFTware Corp.');

The char function creates a 3-by-25 character array mgr_title.

ДОПОЛНЕНИЕ. Последняя команда дает результат аналогичный предыдущим:

mgr_title =

Harold A. Jorgensen

Assistant Project Manager

SFTware Corp. (Конец ДОПОЛНЕНИЯ)