tags:

views:

54

answers:

1

This is my code:

arr = zeros(fx-10,1);
frm = frams(x).cdata;
for k=1:fx-10
    for i=1:10
        for j=1:fy
            arr(k) = arr(k)+ abs(frm(k+i-1,j)-model(i,j))
        end
    end
end

Why the array receive only up to 255 value?

I try to define:

 arr = zeros(fx-10,1,'int64');

and the code failed:

??? Undefined function or method 'plus' for input arguments of type 'int64'.

+3  A: 

Although your array arr is of type double, I believe that one or more of the values you are getting from frm or model is of type UINT8, which has a maximum value of 255. When the arithmetic is done to add these values to arr, I believe the calculation is done using integer arithmetic and the result is converted to a double to be placed in arr. As you keep adding UINT8 values together, the value eventually saturates at the maximum 255.

To get around this, you can use the function DOUBLE to convert values from frm or model to type double before doing the arithmetic. Something like this should work:

arr(k) = arr(k) + abs(double(frm(k+i-1,j))-double(model(i,j)));
gnovice
Thank youIt helped me very much
sari
@sari: Glad to help. Incidentally, if an answer helps solve your problem, you may want to consider marking it as the [accepted answer](http://meta.stackoverflow.com/questions/5234/how-does-accepting-an-answer-work) for your question. In addition to gaining you and the answerer some Rep, it may give people a little more incentive to answer your questions. ;)
gnovice

related questions