Having issue after downloading tabular data from web.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Ron Aditya
am 15 Sep. 2014
Beantwortet: Geoff Hayes
am 15 Sep. 2014
After downloading a table of data from the web and converting the cells to double as I need to analyse these numbers, for some reason the is there are no digits before or after the decimal point it get converted to a whole number.
For example if "v" is the vector consisting of cells
if true
*v=
{'$ 47.21'
'$ .91'
'$ 14.11'
'$ 15'}*
% code
end
After using the following code:
if true
b1=regexp(v,'\d+(\.)?(\d+)?','match');
b(:,1)=str2double([b1{:}]);
% code
end
This is what i get:
b= [ 47.21 91 14.11 15]
instead of b= [ 47.21 0.91 14.11 15]
How do I go about fixing this, no matter what algorithm I use to fix 91 its gonna do the same to 15 as well.
Thanks,
0 Kommentare
Akzeptierte Antwort
Geoff Hayes
am 15 Sep. 2014
b=str2double(regexprep(v,'[^0-9.-]',''))
b =
47.2100
0.9100
14.1100
15.0000
The regexprep replaces all characters that are not 0-9 or '.' or '-' with an empty string. (In regexprep(v,'[^0-9.-]',''), the ^ is the not.)
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!