0
votes

I created a list of names of data files, e.g. abc123.xml, abc456.xml, via

list = dir('folder/*.xml').

Matlab starts this out as a 10x1 struct with 5 fields, where the first one is the name. I extracted the needed data with struct2table, so I now got a 10x1 table. I only need the numerical value as 10x1 double. How can I get rid of the alphanumerical stuff and change the data type?

I tried regexp (Undefined function 'regexp' for input arguments of type 'table') and strfind (Conversion to double from table is not possible). Couldn't come up with anything else, as I'm very new to Matlab.

1
Is every file name guaranteed to have a number in it? - gnovice
Yes. It's generated by some instrument, so the data output is consistent - firefrog

1 Answers

1
votes

You can extract the name fields and place them in a cell array, use regexp to capture the first string of digits it finds in each name, then use str2double to convert those to numeric values:

strs = regexp({list.name}, '(\d+)', 'once', 'tokens');
nums = str2double([strs{:}]);