binary to decimal conversion
古いコメントを表示
i have an array wr(i,j) that is 256X8 in binary. now i need to convert it to decimal. so after conversion the size should be 16x16. i am using bi2de() function but i am unsuccessful to do it. how can i do it?
採用された回答
その他の回答 (1 件)
Kirby Fears
2015 年 9 月 16 日
編集済み: Kirby Fears
2015 年 9 月 16 日
Hi Anika,
I used the following code to convert a 16x16 matrix to binary (256x8) and back with no problems. Please check that you are calling the bin2dec function correctly and wr(i,j) is a "char" array of 1's and 0's. It would help if you post your code, your binary array, and your error message.
m=225*ones(16);
mb=dec2bin(m);
m2=bin2dec(mb);
6 件のコメント
anika hossain
2015 年 9 月 16 日
編集済み: anika hossain
2015 年 9 月 16 日
Kirby Fears
2015 年 9 月 16 日
The char function does not do what you think it does. char(1) returns the first character in the Matlab dictionary of characters, not 1 as a character. You can read the documentation here. Specifically, here is an example from the documentation:
Example: char(65) converts the integer 65 into the character A.
To fix your problem, you can simply recode as follows:
if round(BU(4,4,m))==calc
wb(i,j)='1';
else
wb(i,j)='0';
end
end
Hope this helps.
anika hossain
2015 年 9 月 16 日
Walter Roberson
2015 年 9 月 17 日
And the 256 x 1 double array cannot be reshaped?
anika hossain
2015 年 9 月 17 日
Walter Roberson
2015 年 9 月 17 日
No, bin2dec converts N x M arrays to column arrays of length N. You need to reshape() the result to whatever size you want.
カテゴリ
ヘルプ センター および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!