How can I merge vector elements into a single number of type double?
15 次查看(过去 30 天)
显示 更早的评论
Hello,
How can I transform this vector:
v=[1 2 3]
into this scalar of type double?:
k=123
Thank you,
Lazaros.
0 个评论
采纳的回答
更多回答(2 个)
YT
2019-2-4
编辑:YT
2019-2-4
Something like this?
A = [1 2 3];
joined = str2num(strjoin(num2cell(num2str(A(:))),''));
%>> joined = 123 (type double)
There are probably some more elegant solutions, but this is what I came up with for now.
3 个评论
Guillaume
2019-2-5
Indeed but that is most likely the case I assume.
A simpler, yet more generic solution, using number->string->number conversion:
str2num(strjoin(compose('%d', A), ''))
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!