For replacing the nth item in a list:
replace_nth(N, OldElem, NewElem, List, List2) :-
length(L1, N),
append(L1, [OldElem|Rest], List),
append(L1, [NewElem|Rest], List2).
?- replace_nth(2, OldElem, 666, [0,1,2,3,4,5,6,7], Replaced).
OldElem = 2,
Replaced = [0, 1, 666, 3, 4, 5, 6, 7].
and then combine them:
replace_m_n(Matrix, I, J, NewValue, NewMatrix) :-
replace_nth(I, Old1, New1, Matrix, NewMatrix),
replace_nth(J, _OldElem2, NewValue, Old1, New1).
As for recursion: append/3 is recursive:
append([], List, List).
append([X|Xs], Ys, [X|Zs]) :-
append(Xs, Y, Zs).
and so is length/2:
length([], 0).
length([_|Xs], Len) :-
when((nonvar(Len);nonvar(Len2)), succ(Len2, Len)),
length(Xs, Len2).