I would expect that the values of matrix temp1 would remain unchanged. But somehow the values of matrix temp1 are the same as the values of matrix temp2 at the end of the code.

As Oscar says, temp2 = temp1 just creates a new variable temp2 that is a different name for temp1, not a new underlying object. Consider:

julia> t1 = zeros(5, 5);
julia> t2 = t1;
julia> t2 === t1
true
help?> ===
search: === == !==
===(x,y) -> Bool
≡(x,y) -> Bool
Determine whether x and y are identical, in the sense that no program could distinguish them. First the types of x and y are compared. If those are identical, mutable objects are compared by address in
memory and immutable objects (such as numbers) are compared by contents at the bit level. This function is sometimes called "egal". It always returns a Bool value.
Examples
≡≡≡≡≡≡≡≡≡≡
julia> a = [1, 2]; b = [1, 2];
julia> a == b
true
julia> a === b
false
julia> a === a
true

Understood perfectly now. Many thanks! I have to go over the code from the beginning to see if there are more instances like this. This reasoning is different from Matlab and it was unexpected to me. Thank you once again.