how to concatenate numbers from multiple cells into a single number?
1 回表示 (過去 30 日間)
古いコメントを表示
I have a set of data a = [1 0 1 0 0 1 1 1 0 0] and I would like to turn it into something like n = 1010011100
a is a row vector of varying dimension.
0 件のコメント
回答 (2 件)
Kai Domhardt
2018 年 3 月 28 日
This should do what you need:
n = sum(a.*10.^[length(a)-1:-1:0])
2 件のコメント
Kai Domhardt
2018 年 3 月 28 日
Then you can use David Fletchers answer by storing it as char string. But will not be able to losslessly store n as a numerical (assuming you would use uint64) if the length of a exceeds 20, since intmax('unit64') == 18446744073709551615 == 1.8447e+19
David Fletcher
2018 年 3 月 28 日
You could store it as a char string
a=[1 0 0 0 0 1 1 0 1 0]
b=char(a+48)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!