MATLAB: Locating number from file name

number

I have file names 'Shot 12 Spectra data.mat' (many files where just the number varies). I want to select just the number from the file name. How do I do this please?

Best Answer

Try this:
str = 'Shot 12 Spectra data.mat';
Nr = sscanf(str, '%*s%d')
Nr =
12
EDIT
If the file names are in a cell array:
cel = {'Shot 12 Spectra data.mat'; 'Shot 13 Spectra data.mat'};
Nr = cellfun(@(x)sscanf(x, '%*s%d'), cel)
Nr =
12
13