how to split a string (char value) with zero in front of it but showing the value in the matrix?
조회 수: 1 (최근 30일)
이전 댓글 표시
I have a string of '0100'. i want to split it into binary bit 0 1 0 0. how can i do that?? whenever i turn it into double or integer it turns out 1 0 0,
댓글 수: 0
채택된 답변
추가 답변 (2개)
John D'Errico
2022년 10월 12일
편집: John D'Errico
2022년 10월 12일
MATLAB does NOT allow you to store or represent an integer as the number 0100. If you try, you will get 100. The leading zero goes away. I'm sorry, but it does, and nothing will make that change.
Your simple solution is to NOT convert it into a number. Work with it in terms of strings. Or if you prefer, as a vector of booleans, so 0 or 1 elements.
For example, could you search for leading zeros, counting how many? Yes.
댓글 수: 0
James Tursa
2022년 10월 12일
편집: James Tursa
2022년 10월 12일
Two more ways:
S = '0100';
S=='0' % logical result
S-'0' % double result
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!