how to convert integer array to one value??
조회 수: 23 (최근 30일)
이전 댓글 표시
hi , i want to convert array such as x=[1;2;3;4;5] to one value as y=12345
댓글 수: 0
채택된 답변
Guillaume
2015년 3월 3일
x = [6 0 8 1 3 0];
validateattributes(x, {'numeric'}, {'integer', 'nonnegative', '<', 10});
y = polyval(x, 10)
댓글 수: 4
Guillaume
2015년 3월 3일
If you're going to go through string conversion, this should be the fastest:
y =str2num(char(x + '0'))
That is add ASCII value of '0' to each number and convert the string back to number.
conversions to / from strings are very slow compared to just multiplications / additions, so my initial solution is probably the most efficient.
참고 항목
카테고리
Help Center 및 File Exchange에서 Cell Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!