Having issue after downloading tabular data from web.

1 view (last 30 days)
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,

Accepted Answer

Geoff Hayes
Geoff Hayes on 15 Sep 2014
Ron - perhaps try using regexprep instead as
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.)

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!