The problem with
is that the first index i:n:end is a vector and does not correspond to 1 element. On the other hand, on the righe side, the index i is a sinle element which chooses the row with index i.
You need to change i:n:end to a proper single index accordign to what you want to write to. If you give a numerical example, maybe I can figure what you really want to do.