MATLAB: Extract number from data file name

extraction filename

Hi, I have a list of data file name below :
Data_T2_31_4c_comb_1_9-10-11-12.mat
Data_T2_31_4c_comb_2_9-10-11-13.mat
Data_T2_31_4c_comb_3876_25-26-27-28.mat
I would like to extract the number in the 20th character, so that I will have a list of increasing integers [1 2 .. 3876]. Could you show me how to do that please ! Winn

Best Answer

s={'Data_T2_31_4c_comb_1_9-10-11-12.mat'
'Data_T2_31_4c_comb_2_9-10-11-13.mat'}
out=regexp(s,'\d+','match')
out=str2double(cat(1,out{:}))