what the fault in my code

1 view (last 30 days)
Mohammed Alabiech
Mohammed Alabiech on 27 Aug 2017
Edited: Jan on 28 Aug 2017
I have problem with this code
skAx=1966
skAy=4372
p=5449
Pmlx(1)=10
Pmly(1)=2
Cm3(1)=mod(Pmlx(1)+skAx+skAy,p)
Cm4(1)=mod(Pmly(1)+Cm3(j),p)
when I implement, the result below
Cm3 = 255
Cm4 = 255
while the correct result must be
Cm3 = 899
Cm4 = 901

Accepted Answer

John D'Errico
John D'Errico on 28 Aug 2017
Hint: Don't stuff your results into vectors that are defined to be uint8.
The test is simple.
class(Pmlx)
class(Pmly)
class(cm3)
class(cm4)
One or more of those variables is uint8.
  1 Comment
Jan
Jan on 28 Aug 2017
Edited: Jan on 28 Aug 2017
+1. Example to reproduce this behavior:
a = uint8(16);
a(1) = 1966;
disp(a)
>> 255

Sign in to comment.

More Answers (0)

Categories

Find more on Numeric Types in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!