필터 지우기
필터 지우기

how to concatenate numbers from multiple cells into a single number?

조회 수: 6 (최근 30일)
Daniel Foster
Daniel Foster 2018년 3월 28일
댓글: Kai Domhardt 2018년 3월 28일
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.

답변 (2개)

Kai Domhardt
Kai Domhardt 2018년 3월 28일
This should do what you need:
n = sum(a.*10.^[length(a)-1:-1:0])
  댓글 수: 2
Daniel Foster
Daniel Foster 2018년 3월 28일
Thanks,
I should have mentioned though that 'a' will have in the hundreds of elements. This code ceases to return the correct values for arrays larger than 50~ elements.
Kai Domhardt
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
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)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by