필터 지우기
필터 지우기

Seperating digits of an integer in Simulink

조회 수: 4 (최근 30일)
Rahul
Rahul 2013년 3월 8일
Hello, Is there a block in the Simulink Library which can be used to separate the digits of an integer. Example: If an integer say, 4328 is given as an input to that block, then the expected outputs are '4', '3', '2' and '8'. Can the 'Shift Arithmetic' block be used?
Thanks!

답변 (1개)

TAB
TAB 2013년 3월 8일
You can use normal divide and mod operation to extract the digits.
For example:
Data = 4328;
Dig3 = fix(Data/1000);
Dig2 = fix(mod(Data,1000)/100);
Dig1 = fix(mod(Data,100)/10);
Dig0 = fix(mod(Data,10));
  댓글 수: 2
Rahul
Rahul 2013년 3월 8일
I thought the shift operation, if possible in Simulink, would make the generated code more efficient!Anyway, thanks for the answer!
TAB
TAB 2013년 3월 8일
Shift operation, shifts the bits of the number in binary form, not the digits of decimal number.
Please accept the answer if it helped.

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

카테고리

Help CenterFile Exchange에서 Simulink Functions에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by