Having issue after downloading tabular data from web.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Ron Aditya
el 15 de Sept. de 2014
Respondida: Geoff Hayes
el 15 de Sept. de 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 comentarios
Respuesta aceptada
Geoff Hayes
el 15 de Sept. de 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Web Services en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!