This article is reproduced in other places of the article;matlab Functions1, matlab function
bitset
One of the bits of the set number is 1. Simulink and Signal processing
How to useC =
Bitset(a,bit) Set the bit bits of number A to 1.C = Bitset (a,bit,v) "Simulink and Signal processing" set the bit bits of number A to V,v must be 0 or 1.Application ExamplesExample 1:. C =
Bitset(Uint8 (9), 5) C = 25 The 5th bit of the number 9 (01001) is set to 1,c bits 11001 example 2:c =
Bitset(Uint8 (9), 1,0) C = 8 Sets the 1th bit of the number 9 to 02, the MATLAB function Bitget () 3, the MATLAB function getbit () MATLAB logical symbol XOR:
C=bitxor (A, b);
Bitwise XOR, using the Bitxor function. Bitxor = 3. The basic idea is to convert to binary first, then bitwise XOR, then convert to decimal.
XOR Logic XOR can only handle 1 and 0.
4. function round in MATLAB
Rounding is the nearest integer 5, zeros (m,n) function to establish a full 0 matrix m*n6, Bitget (a,bit) Get number A of the first bit binary value example one:
Decimal 5, written in binary is 101.
Input Dec2bin (5),
Returns the result 101.
Enter Bitget (5,1) to get the lowest bit,
Returns the result 1.
Input Bitget (5,2), get sub-low,
Returns the result 0.
Enter Bitget (5,1) to get the highest bit,
Returns the result 1.
Example two:
Store 5 binary as a matrix.
Xbin=bitget (5,3:-1:1)
Return
[1 0 1]>> Bitget (3,1)
Ans =
1
>> Bitget (3,2)
Ans =
1
>> Bitget (3,3)
Ans =
0
>> Bitget (3,4)
Ans =
07, Matlab uint8 is what type of data ans = unsigned integer should be uint8, indicating that the variable is an unsigned integer, ranging from 0 to 255.
Uint8 refers to 0~2^8-1 = 255 data types, which are generally common in image processing. 8. Ans Evaluates the result variable name 9,use of the rounding function (fix, floor, ceil, round) in MATLAB
Matlab take the whole function
1) fix (x): Truncate rounding.
>> fix ([3.12-3.12])
Ans =
3-3
(2) floor (x): The largest integer not exceeding x. (Gaussian rounding)
>> floor ([3.12-3.12])
Ans =
3-4
(3) Ceil (x): smallest integer greater than X
>> ceil ([3.12-3.12])
Ans =
4-3
(4) Rounding round and rounding
>> Round (3.12-3.12)
Ans =
0
>> round ([3.12-3.12])
Ans =
3-3
In Matlab, the following methods are used in four rounding functions:
Matlab Rounding functions are: fix, floor, ceil, round.
Fix
Rounding in 0 directions, such as fix (-1.3) =-1; Fix (1.3) = 1;
Floor
Rounding in the negative infinity direction, such as floor (-1.3) =-2; Floor (1.3) = 1;
Ceil
Rounding toward positive infinity, e.g. ceil (-1.3) =-1; Ceil (1.3) = 2;
Round
Rounded to the nearest integer, such as round ( -1.3) =-1;round ( -1.52) =-2;round (1.3) =1;round (1.52) = 2.
10. What do you mean by fix (x) in MATLAB?
Fix (X) rounds the elements of X to the nearest integers towards zero. Rounding to 0, example:>> fix (3.2) ans = 3>> fix (3.7) ans = 3>> fix ( -3.7) ans = -3>> fix ( -3.2) ans = 3
11, Matlab How to achieve the bitwise XOR or
g=01001011 q=10100010;
>> clear>> g=uint8 (Bin2dec (' 01001011 '));>> q=uint8 (Bin2dec (' 10100010 '));>> C=dec2bin ( Bitxor (G,Q)) c =11101001>> where the BITXOR is bitwise XOR, the bitwise arithmetic function requires that the input must be the same as an unsigned integer, an unsigned integer array, or a scalar floating-point number, and the output is consistent with the type of input. Dec2bin and Bin2dec are functions that convert binary and decimal to each other. For detailed usage of the above functions, please see Help
12.
Matlab bit operation notes