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?
Mostra commenti meno recenti
st = '23487';
x = double(st);
y = x-48;
y = 2 3 4 8 7
i want this in "normal" format of "23487"...
2 Commenti
Image Analyst
il 24 Nov 2012
Modificato: Image Analyst
il 24 Nov 2012
Is this a Homework question? If so, we'll give hints, but not the answer.
^Or so one would hope...
Here is how to do it without the str2num function:
N = str2double('1234')
Risposta accettata
Più risposte (1)
Andrei Bobrov
il 24 Nov 2012
Modificato: Andrei Bobrov
il 26 Nov 2012
out = (st-'0')*10.^(numel(st)-1:-1:0)';
or from Cody
out = polyval(st-'0',10);
Categorie
Scopri di più su Data Type Conversion in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!