I have cell array of strings with different values:
v = {'12.4B', '145.3M', '34.3M', '1.2B'};
I would like to convert them to numbers. Using sscanf function I can extract only numeric values, but what I want is to multiply the result by billion or million according to the letter.
You can replace
B
andM
withe9
ande6
respectively (scientific notation) using regular expression replacement (regexp
) and then convert the resulting strings to a number withstr2double
.You can obviously expand this to include any other necessary conversions.
And as an example showing what's happening: