I have a problem : suppose I have a matrix
A =
-1 2 -3
-4 5 -6
-7 8 -9
I convert it into a column matrix
B = A(:)
B =
-1
-4
-7
2
5
8
-3
-6
-9
Suppose I want to force the first column elements to lie within a particular range (-range1 : range1) , second column elements within (-range2 : range2) & third column elements within (-range3:range3). I tried doing that by implementing this code :
range1 = 0;
range2 = -5;
range3 = 0;
B(B(1:3,1)<range1)=10;
B(B(4:6,1)>range2)=0;
B(B(7:9,1)<range3)=20;
The answer I get is this :
B =
20
20
20
2
5
8
-3
-6
-9
Whereas the correct answer I should get is this :
B =
10
10
10
0
0
0
20
20
20
What I am doing wrong ? Please help.