MATLAB Answers

How to subtract single element of matrix from any number

5 views (last 30 days)
rahul ahire
rahul ahire on 5 Mar 2019
Answered: Walter Roberson on 5 Mar 2019
i am having a matrix 'devi1' and graylevel image 'b'
a variable av2 is having value 79
my code is
b(1,1)=abs(a(1,1)-av2);
currently a(1,1)=0
then b(1,1) should be 78
but it is caming '0'
please help me !

Answers (1)

Walter Roberson
Walter Roberson on 5 Mar 2019
abs(double(a(1,1)) - av2)
Your array is uint8. When you subtract a larger value from a uint8 value, then the result does not become negative: the result is uint8 and so the result becomes 0. You need to convert to a signed representation to avoid the problem.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by