how to split a string (char value) with zero in front of it but showing the value in the matrix?
2 次查看(过去 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!