i get an error.whats wrong? why the values of 'B' in intger instead of decimal.

1 view (last 30 days)
II=[14 23;44 15];
R=II(:)';
x=0.3;
p=0.343;
for n=2:4;
if x(n-1)>=0 & x(n-1)<=p
x(n)=x(n-1)/p;
else
x(n)=(1-x(n-1))/(1-p);
end
end
A=sort(x);
[A,T]=sort(x);
Y=R(T);
C=reshape(Y,[2,2]);
r = 3.8;
L(1)= 0.234;
for i=2:4
L(i) = r*L(i-1)*(1-L(i-1));
end
mm=min(L);
nn=max(L);
oo=nn-mm;
Z=uint8(8*((L-mm)/oo))+1;
%for i=1:9
%K(i)=mod((abs(L(i))-floor(abs(L(i))))*1e14,50);
%end
CC(1)=bitxor(mod(157,50),mod(Y(1)+Z(1),50));
for i=2:4
CC(i)=bitxor(mod(CC(i-1),50),mod(Y(i)+Z(i),50));
end
ZZ=reshape(CC,[2,2]);
B=ZZ/10
why the value of B in intger.?

Accepted Answer

KALYAN ACHARJYA
KALYAN ACHARJYA on 8 Jul 2019
Edited: KALYAN ACHARJYA on 8 Jul 2019
See your zz data is integer type (uint8).
>> whos ZZ
Name Size Bytes Class Attributes
ZZ 2x2 4 uint8
Hence
ZZ =
2×2 uint8 matrix
31 18
10 35
Now ZZ/10
B =
2×2 uint8 matrix
3 2
1 4
Souce stackoverflow{dor}com: Converting both integer values to a double precision value will ensure that MATLAB performs floating point division instead of integer division (which will round off the result). See this link
But when you convert zz to double
B=double(ZZ)/10
format shortg
See the results
B =
3.1 1.8
1 3.5

More Answers (0)

Community Treasure Hunt

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

Start Hunting!