I see people take ==
, ~=
, >
, <
between matrixes with a different dimension in parentheses following a matrix to get its entries, like this:
b =
1 4 7
2 5 8
3 6 9
>> b == [1 2 3]
ans =
3×3 logical array
1 0 0
0 0 0
0 0 0
>> b == [1 4 7]
ans =
3×3 logical array
1 1 1
0 0 0
0 0 0
>> b == [1 4 5]
ans =
3×3 logical array
1 1 0
0 0 0
0 0 0
>> b == [1 5 4]
ans =
3×3 logical array
1 0 0
0 1 0
0 0 0
>> a
a =
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
>> a(:, b == [1 4 5])
ans =
1 4
1 4
1 4
>> a(:, b == [1 5 4])
ans =
1 5
1 5
1 5
>> b
b =
1 4 7
2 5 8
3 6 9
>> b > [1 3 2]
ans =
3×3 logical array
0 1 1
1 1 1
1 1 1
However, I have no idea why these would work. Any explanation about this usage? (My English is not good to describe the question better, hope anyone could edit this question to make it more understandable? Thanks in advance!)