23.06.2015 Views

MATLAB Programming

MATLAB Programming

MATLAB Programming

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Creating and Concatenating Matrices<br />

Combining Unlike Integer Types<br />

If you combine different integer types in a matrix (e.g., signed with unsigned,<br />

or 8-bit integers with 16-bit integers), <strong>MATLAB</strong> returns a matrix in which all<br />

elements are of one common type. <strong>MATLAB</strong> sets all elements of the resulting<br />

matrix to the data type of the left-most element in the input matrix. For<br />

example, the result of the following concatenation is a vector of three 16-bit<br />

signed integers:<br />

A = [int16(450) uint8(250) int32(1000000)]<br />

<strong>MATLAB</strong> also displays a warning to inform you that the result may not be<br />

what you had expected:<br />

A = [int16(450) uint8(250) int32(1000000)];<br />

Warning: Concatenation with dominant (left-most) integer class<br />

may overflow other operands on conversion to return class.<br />

You can disable this warning by entering the following two commands directly<br />

after the operation that caused the warning. The first command retrieves<br />

the message identifier associated with the most recent warning issued by<br />

<strong>MATLAB</strong>. The second command uses this identifier to disable any further<br />

warnings of that type from being issued:<br />

[msg, intcat_msgid] = lastwarn;<br />

warning('off', intcat_msgid);<br />

To reenable the warning so that it will now be displayed, use<br />

warning('on', intcat_msgid);<br />

You can use these commands to disable or enable the display of any <strong>MATLAB</strong><br />

warning.<br />

Example of Combining Unlike Integer Sizes. After disabling the integer<br />

concatenation warnings as shown above, concatenate the following two<br />

numbers once, and then switch their order. The return value depends on the<br />

order in which the integers are concatenated. The left-most type determines<br />

thedatatypeforallelementsinthevector:<br />

A = [int16(5000) int8(50)]<br />

A =<br />

1-13

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!