i need to convert a string to a num without using the "str2num" function but in the final answer i have some undesired spaces. how can i remove them?

2 views (last 30 days)
st = '23487';
x = double(st);
y = x-48;
y = 2 3 4 8 7
i want this in "normal" format of "23487"...

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 24 Nov 2012
Edited: Azzi Abdelmalek on 24 Nov 2012
st = '14523'
x = double(st)
y = sum((x-48).*10.^(numel(st)-1:-1:0))

More Answers (1)

Andrei Bobrov
Andrei Bobrov on 24 Nov 2012
Edited: Andrei Bobrov on 26 Nov 2012
out = (st-'0')*10.^(numel(st)-1:-1:0)';
or from Cody
out = polyval(st-'0',10);

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!