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!