When you do
finalMatrix(finalMatrix(9:12,1) == 1,1) = 99;
you will actually replace the first 4 elements of finalMatrix
, assuming that the corresponding values in 9:12
were ==1
. The reason is that Matlab does the following steps:
1) generate a 4x1 matrix finalMatrix(9:12,1)
2) figure out which of the four elements is ==1
3) return a boolean array (four elements long) corresponding to those elements
4) perform logical indexing on finalMatrix with these four elements -
which now reference the first four elements of the first column of finalMatrix
You just need
finalMatrix(9:12,1) = 99;
Or, if you care that the values were 1 to begin with, you could do
indx = find(finalMatrix(9:12,1)==1);
finalMatrix(indx+8,1)=1;