MATLAB QUESTION
Answer Sheet for L16: Logical Vectors and Image Processing in MATLAB
1. Exploring Logical Vectors
Define a = [-2 -1 0 1 2] and b = [0 -3 -2 1 4]. Predict the result of each of the following logical MATLAB expressions:
Problem
MATLAB expression
Predicted Result
MATLAB result (if different)
1
>> ~a
2
>> a & b
3
<<
4
>> b > 0
5
>> a == b
6
>> a > b
7
<<
8
<<
9
<<
10
>> a(~(~a))
11
>> (b .^ 2) .* (b > 0)
12
>> (a .^ 2) .* (-1 * (a < 0))
13
<<
14
>> sum(a > 0)
15
>> sum(a .* (a > 0))
16
>> any(a > b)
17
<<
18
>> find(a > b)