| Communications Toolbox | ![]() |
To compare corresponding elements of two Galois arrays that have the same size, use the operators == and ~=. The result is a logical array, each element of which indicates the truth or falsity of the corresponding elementwise comparison. If you use the same operators to compare a scalar with a Galois array, then MATLAB compares the scalar with each element of the array, producing a logical array of the same size.
m = 5; r1 = gf([1:3],m); r2 = 1 ./ r1; lg1 = (r1 .* r2 == [1 1 1]) % Does each element equal one? lg2 = (r1 .* r2 == 1) % Same as above, using scalar expansion lg3 = (r1 ~= r2) % Does each element differ from its inverse?
The output is below.
lg1 =
1 1 1
lg2 =
1 1 1
lg3 =
0 1 1
To compare entire arrays and obtain a logical scalar result rather than a logical array, you can use the built-in isequal function. Note, however, that isequal uses strict rules for its comparison, and returns a value of 0 (false) if you compare
A Galois array with an ordinary MATLAB array, even if the values of the underlying array elements match
A scalar with a nonscalar array, even if all elements in the array match the scalar
The example below illustrates this difference between == and isequal.
m = 5; r1 = gf([1:3],m); r2 = 1 ./ r1; lg4 = isequal(r1 .* r2, [1 1 1]); % False lg5 = isequal(r1 .* r2, gf(1,m)); % False lg6 = isequal(r1 .* r2, gf([1 1 1],m)); % True
| Logical Operations in Galois Fields | Testing for Nonzero Values | ![]() |
© 1994-2005 The MathWorks, Inc.