MATLAB: Why same matrix gives different answers

same matrix different answers.

My problem : I want to get index of all elements in matrix "B" whose value is equal to minimum value of matrix "B".
Using some computations I obtained Matrix "B",when I use the function file named "New_get_index.m" in same code it gives following answer.
Sub2 =
1 1
2 1
when I provide same matrix "B" as known matrix in file " test_2.m" and use function file named "New_get_index.m" It gives following answer.
Sub2 =
1 1
2 1
1 2
2 2
the code of both files are as follows,
1] code of " test_2.m":-
B=[ -0.1600 -0.1600 -0.0350 0.2150 0.5900 0.8400;
-0.1600 -0.1600 -0.0350 0.2150 0.5900 0.8400;
-0.0350 -0.0350 0.0900 0.3400 0.7150 0.9650;
0.2150 0.2150 0.3400 0.5900 0.9650 1.2150;
0.5900 0.5900 0.7150 0.9650 1.3400 1.5900;
0.8400 0.8400 0.9650 1.2150 1.5900 1.8400]
Z=B
Sub2=New_get_index(Z)
2] code of "New_get_index.m" :-
function Sub2=New_get_index(Z)
B=Z
A=B(:)
C=min(A)
[r c] = find(A==C)
[D{1:ndims(B)}] = ind2sub(size(B), r(:)) ;
Sub2 = cat(2,D{:})
Thanks.

Best Answer

After your computations of B, give the command at the command line
format long g
and then display B. You will almost certainly find that it is not exactly the same as the B you code into test_2.m