How to subtract single element of matrix from any number

1 次查看(过去 30 天)
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 !

回答(1 个)

Walter Roberson
Walter Roberson 2019-3-5
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.

类别

Help CenterFile Exchange 中查找有关 Data Types 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by