Combining elements in an array
조회 수: 4 (최근 30일)
이전 댓글 표시
Hi, I have a logical array, A = [1 0 1]. How can I combine the elements horizontally, so that I have B = [101]? Any help would be appreciated! SS
댓글 수: 0
채택된 답변
Star Strider
2016년 7월 12일
To turn your logical array into a double array, any mathematical operation on it will do the conversion. Here I used ‘+’:
A = logical([1 0 1])
An = +A
whos A*
A =
1 0 1
An =
1 0 1
Name Size Bytes Class Attributes
A 1x3 3 logical
An 1x3 24 double
댓글 수: 0
추가 답변 (1개)
James Tursa
2016년 7월 12일
편집: James Tursa
2016년 7월 12일
Assuming you intend to combine the individual digits into a single decimal number:
B = sum(A.*(10.^(numel(A)-1:-1:0)));
If you intended to make a string instead, then
B = char(A+'0');
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Numeric Types에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!