tags:

views:

65

answers:

1
+1  Q: 

basic matlab help

matlab is acting weird. if I assign the value 202 to variable a and 207 to variable b then add a+b it gives me the correct answer 409. Now if I subtract a-b it gives me 0 instead of -5. btu if I do 202-207(not using the variables a and b ) it gives me -5.

what could be causing this?

edit: it gets even weird. I just noticed that matlab gives me a-b=0 only when I assign it the values 202 and 207 from a data matrix a=data(1,1),b=data(2,1). if I assign the values directly to a and b it acts normal

+8  A: 
a = uint8(202);
b = uint8(207);

>> a-b
ans =
    0

>> 202-207
ans =
    -5
Amro
I just converted my whole matrix from uint8 to int8 but it does the same thing.
anon
`int8` has a range of [-128,+127], so `a=int8(202)` will store the maximum 127.
Amro

related questions