Convert binary values to a decimal matrix

1 回表示 (過去 30 日間)
Youssra
Youssra 2015 年 12 月 2 日
コメント済み: Youssra 2015 年 12 月 2 日
Hello, Suppose that I have a matrix a= [1 3; 4 2], I convert this matrix to binary format using this code:
a=magic(2)
y=dec2bin(a,8)
e=str2num(y(:))';
The result is :
y =
00000001
00000100
00000011
00000010
e =
Columns 1 through 17
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Columns 18 through 32
0 0 0 0 1 0 0 0 0 1 1 1 0 1 0
Now when I want to get back my original matrix I inverse the function : s=num2str(e(:))'; r=bin2dec(s)
The results I got is:
r =
1082
What can I do to get the orignal matrix? not a number Thank you in advance

採用された回答

Thorsten
Thorsten 2015 年 12 月 2 日
aback = reshape(bin2dec(num2str(reshape(e, 4, []))), 2, 2);
  1 件のコメント
Youssra
Youssra 2015 年 12 月 2 日
that works perfectly ^^. Thank youuuu

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by