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

1 回表示 (過去 30 日間)
Sultan Mehmood
Sultan Mehmood 2019 年 7 月 8 日
編集済み: Stephen23 2019 年 7 月 10 日
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.?

採用された回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 7 月 8 日
編集済み: KALYAN ACHARJYA 2019 年 7 月 8 日
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
  2 件のコメント
Sultan Mehmood
Sultan Mehmood 2019 年 7 月 10 日
thanku
Stephen23
Stephen23 2019 年 7 月 10 日
編集済み: Stephen23 2019 年 7 月 10 日
The MATLAB documentation explains the expected output classes for operations on integers:

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB Coder についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by