필터 지우기
필터 지우기

Please I need help in MATLAB!!

조회 수: 1 (최근 30일)
Samira Zeinab
Samira Zeinab 2016년 10월 25일
댓글: xiexiezaijian 2016년 10월 26일
I have to write a function that changes binary numbers to decimal numbers without using loops and without using the function bin2dec.
  댓글 수: 1
Adam
Adam 2016년 10월 25일
If you have to write the function then write it. Then come and ask for help once you have made some effort.

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

답변 (2개)

xiexiezaijian
xiexiezaijian 2016년 10월 25일
since no loops and no bin2dec, this work could be done using the definition of binary number and vecterization operation. Take binary number 101 for example:
a = 101;
b = str2num(num2str(a)');
c = 2.^(2:-1:0)*b;%get the decimal number here
it is easy to handle the binary number with 4 or more digits and even numbers with points.
It seems that this is a question in MATLAB Cody.....
  댓글 수: 2
Samira Zeinab
Samira Zeinab 2016년 10월 25일
I cannot use str2num . I have to use the point-wise operator :^ (dot ^ ) and the matrix multiplication operator applied to vectors. In particular, if u is a 1 by n vector and v is an n by 1 vector, then u v is the scalar given by u v = Σn i=1 u(i) v(i).)
xiexiezaijian
xiexiezaijian 2016년 10월 26일
If no str2num......maybe you could do like this;
a = 101;
b = num2str(101) - '0';% since '1'-'0' = 1;
c = 2.^(2:-1:0)*b';
really like a Cody problem....

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


Walter Roberson
Walter Roberson 2016년 10월 25일
Hint: 2 to the 0, 2 to the 1, 2 to the 2, 2 to the 3... is 2 to the vector 0:3. Multiply each of those by the corresponding digit of the input and add the results

카테고리

Help CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by