Extract numeric data from cell
70 views (last 30 days)
Show older comments
I need to extract numbers from a cell and put them in a matrix.
My cell is expressed as following:
A={'position: [0.5418702363967896, 0.0005752428551204503, -3.834952076431364e-05, 0.0, 0.0, 0.0]'};
I tried the following example but it does not consider the e-5 .
A1 = regexp(A,'[\d*\.]*\d*','match')
A2 = [A1{:}]
out = str2double(strcat(A2{:}))
I need to get the full number to be able to make some calculations.
Thank you for help.
3 Comments
Accepted Answer
Mathieu NOE
on 9 Feb 2021
hello
A = {'position: [0.5418702363967896, 0.0005752428551204503, -3.834952076431364e-05, 0.0, 0.0, 0.0]'};
A1 = regexp(char(A),'[-+]?([0-9]*[.])?[0-9]+([eE][-+]?\d+)?','match'); % extract numerical content of string
out = str2double(A1);
More Answers (1)
Jan
on 9 Feb 2021
A = ['position: [0.5418702363967896, 0.0005752428551204503, ', ...
'-3.834952076431364e-05, 0.0, 0.0, 0.0]'];
D = extractBetween(A, '[', ']');
data = sscanf(D{1}, '%g,')
See Also
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!