Binary string to double array

28 ビュー (過去 30 日間)
Mariam Hossam
Mariam Hossam 2020 年 3 月 14 日
回答済み: Sriram Tadavarty 2020 年 3 月 14 日
I want to convert this string of binary message=110110111000011110010110100111000011101101 (1x42 char) to double array not cells (1x42)double but everytime I use the casteing double(message) I get string of 49 49 49 48 48 ... Ps;message was originally text and I translated it using dec2bin. Please help

回答 (2 件)

Sriram Tadavarty
Sriram Tadavarty 2020 年 3 月 14 日
Hi Mariam,
To convert string array to double array, compare it with character '1' and convert to double
logicalMessage = message == '1';
doubleArray = double(logicalMessage);
Hope this helps.
Regards,
Sriram

Walter Roberson
Walter Roberson 2020 年 3 月 14 日
The sequence is not double and should not be converted to double.
char(bin2dec(reshape(message, 7,6).').')
The conversion to binary was faulty: the dec2bin() call should have had the second parameter 8 instead of no second parameter. If that were corrected then the 7 in my code would change to 8

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by