how to convert a vector to a number

5 views (last 30 days)
hi lets say i have a vector [1,1,1] is there a function that can convert this to the number 111 ?
Itzik Ben Shabat
Itzik Ben Shabat on 16 Dec 2012
the vector does not contain values greater than 9. if it has 0 to the left it ignores them - 009=9, 012=12 etc.
i could write a for loop that calculates this but i was wondering if there is a function.

Sign in to comment.

Accepted Answer

José-Luis on 16 Dec 2012
Edited: José-Luis on 16 Dec 2012
a = randi(9,1,5);
your_num = sscanf(sprintf('%d',a),'%d');
alt_sol = sum(a.*repmat(10,1,numel(a)).^(numel(a)-1:-1:0));

More Answers (0)


Find more on Startup and Shutdown 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!

Translated by