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!