답변 (1개)

Roger Stafford
Roger Stafford 2017년 3월 16일
편집: Roger Stafford 2017년 3월 16일

0 개 추천

function s = binstr(x)
if ~isfinite(x)|(length(x)~=1), error('x must be a finite scalar.'),end
b = (x<0); x = abs(x);
s = zeros(1,53);
[f,e] = log2(x);
for i = 1:53
f = 2*f;
d = floor(f);
f = f - d;
s(i) = d+48;
end
s = ['0.' s sprintf('*2^(%d)',e)];
if b, s = ['-' s]; end
s = char(s);
return

댓글 수: 9

Pratik Anandpara
Pratik Anandpara 2017년 3월 16일
where to put 9.2532
Pratik Anandpara
Pratik Anandpara 2017년 3월 16일
without function file it is possible?
binstr(9.2532)
Pratik Anandpara
Pratik Anandpara 2017년 3월 16일
still error i save this file as binstr name and at binstr(9.2532) not seen output
Pratik Anandpara
Pratik Anandpara 2017년 3월 16일
Undefined function 'finite' for input arguments of type 'double'.
Error in binstr (line 2) if ~finite(x)|(length(x)~=1), error('x must be a finite scalar.'),end
Roger Stafford
Roger Stafford 2017년 3월 16일
편집: Roger Stafford 2017년 3월 16일
The function should generate a string which consists of binary digits with a binary point and a power of two. Write
s = binstr(9.2532)
and display the string. The string I get on my ancient computer is:
0.10010100000011010001101101110001011101011000111000100*2^4
Pratik Anandpara
Pratik Anandpara 2017년 3월 16일
편집: Pratik Anandpara 2017년 3월 16일
s=binstr(9.2532)
Undefined function 'finite' for input arguments of type 'double'.
Error in binstr (line 2) if ~finite(x)|(length(x)~=1), error('x must be a finite scalar.'),end
Pratik Anandpara
Pratik Anandpara 2017년 3월 16일
s=binstr(9.2532) i edit this in command window or function file
Roger Stafford
Roger Stafford 2017년 3월 16일
Change 'finite' to 'isfinite'.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

제품

태그

아직 태그를 입력하지 않았습니다.

질문:

2017년 3월 16일

편집:

2017년 3월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by