You have
maxU = max(U)
by default, max() operates along the first non-scalar dimension. Your U is a 2D array so max(U) is going to be the same as max(U,1), finding the per-column maximums.
Then you have
index1 = find(U(1,:)== maxU);
This matches the first row against the per-column maximums, and that comparison would only be true somewhere if something in the first row happened to be the exact same as the per-column maximums for that column. The same for the second and third rows. If you consider a matrix such as
[0 0 0; 0 0 0; 0 0 0; 1 1 1]
then max() of that would be [1 1 1] and you can see that none of those maximum values happen to occur in the first three rows. Your matrix is a lot bigger than 3 rows, so you cannot expect that you will definitely find matches in the first three rows.