1

I'm new to Matlab. I have these simple lines. The problem is that the sum variable does not take negative values. All variables are double.

 Inp_pixel = Inp_padded(x, y);
 Filter_pixel = Filter(f_row, f_col);
 sum = sum + (Inp_pixel * Filter_pixel);

for example: if Filter_pixel = -1 and Inp_pixel = 150 and sum = 0. the expected result should be -150 but I get sum = 0

5
  • 1
    I get all negative values!!! But then, I had to make up values for Inp_padded, x, y, Filter, f_row, f_col, and sum and I'm notorious for picking the wrong values. Commented Apr 8, 2020 at 15:31
  • more clarification please. Commented Apr 8, 2020 at 15:40
  • what exactly do you want to do? if you can't describe your problem clear enough, it is hard for other people to guess what you want to do and help you out. Commented Apr 8, 2020 at 15:40
  • my problem is in the SUM variable. it ignores the negative values. Commented Apr 8, 2020 at 15:45
  • more clarification please. Commented Apr 8, 2020 at 16:27

1 Answer 1

1

The problem was in Inp_pixel. This variable assigned from an uint8 2D array. that's why this variable didn't take the negative value of the multiplication. I used cast() function to solve this problem. for more details about this function please check this link. MATLAB documentation page

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.