I have a binary matrix lets say b = [1 0 0; 1 1 1; 0 1 0], now I want the output matrix as c = [100; 111; 010] , I want to join all the binary values of all columns into one, then all the binary values of all columns of 2nd row into one as a huge binary strings and want output as single column vector. How should I do this.

回答 (1 件)

Guillaume
Guillaume 2018 年 5 月 11 日

0 投票

c = sum(b .* 10.^(size(b, 2)-1:-1:0), 2)
Of course, matlab displays the number 010 as 10. If you do want the display 010, then c cannot be numeric.

2 件のコメント

varsha sachdeva
varsha sachdeva 2018 年 5 月 11 日
Its giving an error..
Guillaume
Guillaume 2018 年 5 月 11 日
You're using a version prior to R2016b. With old versions:
c = sum(bsxfun(@times, b, 10.^(size(b, 2)-1:-1:0)), 2)

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

カテゴリ

ヘルプ センター および File ExchangeSimulink についてさらに検索

質問済み:

2018 年 5 月 11 日

コメント済み:

2018 年 5 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by