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?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
st = '23487';
x = double(st);
y = x-48;
y = 2 3 4 8 7
i want this in "normal" format of "23487"...
2 commentaires
Image Analyst
le 24 Nov 2012
Modifié(e) : Image Analyst
le 24 Nov 2012
Is this a Homework question? If so, we'll give hints, but not the answer.
Réponse acceptée
Azzi Abdelmalek
le 24 Nov 2012
Modifié(e) : Azzi Abdelmalek
le 24 Nov 2012
st = '14523'
x = double(st)
y = sum((x-48).*10.^(numel(st)-1:-1:0))
Plus de réponses (1)
Andrei Bobrov
le 24 Nov 2012
Modifié(e) : Andrei Bobrov
le 26 Nov 2012
out = (st-'0')*10.^(numel(st)-1:-1:0)';
or from Cody
out = polyval(st-'0',10);
0 commentaires
Voir également
Catégories
En savoir plus sur Data Type Conversion dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!