How do I extract multiple numbers from a string or character vector?
Show older comments
I have a list of mixed text and numerical information that was generated by a third party software as an Excel file... example shown here:
7 mins 12 secs
12 mins 54 secs
1 min 1 sec
3 mins 5 secs
I want to calculate a single number of seconds for the total time represented by this information for each instance (so, '7mins 12 secs' would become 432.)
I have imported the original data into Matlab as a cell aray of character vectors, converted the cell array to a character array (time_taken_pre_char), and tried using the sscanf as
sscanf(time_taken_pre_char(1),'%d mins %d secs')
ans =
7
However, this doesn't work for the 'secs' numbers and I want to extract all the numbers into a cell array for simple multiplication; generating something like
[7, 12; 12, 54; 1, 1; 3, 5]
Any help is greatly appreciated!
Accepted Answer
More Answers (0)
Categories
Find more on Characters and Strings 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!