0

I have the following function, provided that the code for pdist2 is here.

function m = pixel_minimize_distance(x,y)

maximum = (sum(sum(pdist2(x,y))));
[r c] = size(y);
initialValue = y(1,1);
for i=1:r
    for j=1:c
        o = y(i,j);
        y(i,j) = 0;
        sum2 = (sum(sum(pdist2(x,y))));


        if sum2 >= maximum
            if o ~= 0
                maximum = sum2;
                m = o;
            end
        maximum = maximum;
        m = initialValue;
        end
        y(i,j)=o;
    end
    end
end

Now, when I try to run the function, I don't get an output as shown below:

>> A=[0 0 0; 0 0 0];
>> B=[1 1 1; 1 1 1];
>> pixel_minimize_distance(A,B)

How can I solve this issue?

Thanks.

Simplicity
  • 47,404
  • 98
  • 256
  • 385
  • It is not a good practice [to use `i` and `j` as variables in matlab](http://stackoverflow.com/questions/14790740/using-i-and-j-as-variables-in-matlab) – Shai Feb 14 '13 at 14:17

2 Answers2

2

don't call the variable maximum as it is a Matlab function (Simulink's, actually).

Still, do you know that

maximum=maximum

is not doing nothing?

alsodo you know that the line

if sum2 >= maximum

is not doing nothing neither? sum2 is never being updated, well beter say, it is several times being updated WITH THE SAME VALUE. check your code, it has little sense rigth now.

EDIT: maybe with some different matrixes will do something.... but with the ones you provide not.

Ander Biguri
  • 35,140
  • 11
  • 74
  • 120
1

Since you replace the (i,j) element of y with 0 after reading it here:

o = y(i,j); y(i,j) = 0;

and since all entries of y are positive in your test case, the condition:

if sum2 >= maximum

never evaluates to true. Consecutively, the output variable m gets never initialized hence the function returns nothing.

Try to initialize m at the start of your function to empty or some other default value that would make sense.

upperBound
  • 680
  • 4
  • 11