convert decimal values to binary?

1 回表示 (過去 30 日間)
SNEHA P S
SNEHA P S 2017 年 7 月 19 日
コメント済み: SNEHA P S 2017 年 7 月 19 日
xa(1)=0;
ya(1)=0;
a=1.4;
b=0.3;
sa=0;
for i=2:41616
xa(i)=1-a*(xa(i-1)^2)+ya(i-1);
ya(i)=b*xa(i-1);
sa(i) = mod (ya(i)* (10^12) , 256);
sabinary(i) = dec2bin(round(sa(i) * (2^10)), 8) - '0';
end
This is the code to find 'sa'. I got values for sa(i) but i cant convert those values of 1D array to binary. Please help me with the above code.
  1 件のコメント
Stephen23
Stephen23 2017 年 7 月 19 日
編集済み: Stephen23 2017 年 7 月 19 日
@SNEHA P S: what do you expect the output to be? How do you expect to put a non-scalar char vector (the output from dec2bin) into one single element of sabinary ?

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

採用された回答

Walter Roberson
Walter Roberson 2017 年 7 月 19 日
The following is for R2016b or later, specifically to use a facility that allows the entire binary value to be stored into a single location, since that is how you seem to expect the output to be.
xa(1)=0;
ya(1)=0;
a=1.4;
b=0.3;
sa=0;
N = 41616;
sabinary = strings(1, N);
sabinary(1) = string('00000000');
for K = 2:N
xa(K)=1-a*(xa(K-1)^2)+ya(K-1);
ya(K)=b*xa(K-1);
sa(K) = mod (ya(K)* (10^12) , 256);
sabinary(K) = string(dec2bin(round(sa(K) * (2^10)), 8));
end
sa_recovered = bin2dec(sabinary) / 2^10;
  1 件のコメント
SNEHA P S
SNEHA P S 2017 年 7 月 19 日
Thank u

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by