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 次查看(过去 30 天)
显示 更早的评论
st = '23487';
x = double(st);
y = x-48;
y = 2 3 4 8 7
i want this in "normal" format of "23487"...
2 个评论
Image Analyst
2012-11-24
编辑:Image Analyst
2012-11-24
Is this a Homework question? If so, we'll give hints, but not the answer.
采纳的回答
Azzi Abdelmalek
2012-11-24
编辑:Azzi Abdelmalek
2012-11-24
st = '14523'
x = double(st)
y = sum((x-48).*10.^(numel(st)-1:-1:0))
更多回答(1 个)
Andrei Bobrov
2012-11-24
编辑:Andrei Bobrov
2012-11-26
out = (st-'0')*10.^(numel(st)-1:-1:0)';
or from Cody
out = polyval(st-'0',10);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!