Programming Fundamentals - The MathWorks - #39

/ 840


catalogue search
P. 01
P. 02
P. 03
P. 04
P. 05
P. 06
P. 07
P. 08
P. 09
P. 10
P. 11
P. 12
P. 13
P. 14
P. 15
P. 16
P. 17
P. 18
P. 19
P. 20
P. 21
P. 22
P. 23
P. 24
P. 25
P. 26
P. 27
P. 28
P. 29
P. 30
P. 31
P. 32
P. 33
P. 34
P. 35
P. 36
P. 37
P. 38
P. 39
P. 40
P. 41
P. 42
P. 43
P. 44
P. 45
P. 46
P. 47
P. 48
P. 49
P. 50


See other catalogues for The MathWorks

Text version of the page
Creating and Concatenating Matrices
C =
50 127
Note You can find the maximum or minimum values for any MATLAB integer type using the intmax and intmin functions. For floating-point types, use realmax and realmin.
Example of Combining Signed with Unsigned. Now do the same exercise with signed and unsigned integers. Again, the left-most element determines thedatatypeforallelementsintheresultingmatrix:
A = [int8(-100) uint8(100)] A =
-100 100
B = [uint8(100) int8(-100)] B =
100 0
The element int8(-100) is set to zero because it is no longer signed.
MATLAB evaluates each element prior to concatenating them into a combined array. In other words, the following statement evaluates to an 8-bit signed integer (equal to 50) and an 8-bit unsigned integer (unsigned -50 is set to zero) before the two elements are combined. Following the concatenation, the second element retains its zero value but takes on the unsigned int8 type:
A = [int8(50), uint8(-50)]
A= 50 0
Combining Integer and Noninteger Data
If you combine integers with double, single,or logical classes, all elements ofthe resulting matrix are given the data type ofthe left-most integer. For example, all elements of the following vector are set to int32:
A= [true pi int32(1000000) single(17.32) uint8(250)]
1-15

pageCatalog pdf di En 2012-06-22-01