i had expected to have dimension error in line 6 but it did not
I would expect an error if the if condition is true when n <= 24, since the n-24 would then be an invalid index for Signal.There would also be an error if n+window-25 is greater than size(signal, 2).
But otherwise, I would not expect any error. You're putting a 2D slice into another 2D slice. I would expect however lots of 0s in your response matrix due to the way its constructed.
To show you how the matrix is filled, let's assume that response does not exist yet, that epoch is 1, window is 10 and the if becomes true for n = 30. At that step, let's assume StimulusCode returns 6, the assignment is thus:
Response(6, 1, :, :) = Signal(1, 6:15, :);
which means that
Response(1, 1, :, :) to Response(1, 1, :, :) gets filled with 0s. Response(6, 1, 1, :) gets filled with Signal(1, 6, :), Response(6, 1, 2, :) gets filled with Signal(1, 7, :), etc. Response(6, 1, 10, :) gets filled with Signal(15, :).