how to convert a single row matrix into a number (double)
8 views (last 30 days)
Show older comments
how to convert a single row matrix into a number (double) for exemple: [1 2 3 4 5] into 12345
0 Comments
Accepted Answer
Rik
on 6 Feb 2018
a=[1 2 3 4 5];
b=str2double(sprintf('%d',round(a)));
Another method would be to use positional information:
a=[1 2 3 4 5];
b=sum(a.*10.^((length(a)-1):-1:0));
This second method will often work better, but if values larger than 9 are present in a, this will not return the result you might mean.
1 Comment
Rik
on 6 Feb 2018
You might be able to correct the powers of 10 vector with cumsum(a>10), or more directly with floor(log10(a))
See Also
Categories
Find more on Numeric Types in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!