How to remove both leading and trailing zeros from a binary string?
8 ビュー (過去 30 日間)
古いコメントを表示
Let
A=[00000001111; 00000110010; 10111011100; 00001000110; 11111010000; 00000001010]
I want to remove zeroes from both left and right side of each binary representation. That is
Answer should be
Ans=[1111; 11001; 101110111; 100011; 1111101; 101]
I have tried 'short format g'.
0 件のコメント
採用された回答
per isakson
2021 年 4 月 30 日
編集済み: per isakson
2021 年 4 月 30 日
Is this what you look for?
%%
A=["00000001111";"00000110010";"10111011100";"00001000110";"11111010000";"00000001010"];
%%
B = regexprep( A, "^[0]+", "" );
B = regexprep( B, "[0]+$", "" )
Notice that dec2bin() returns a character row, not double
dec2bin( 123, 16 )
その他の回答 (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!