MATLAB: Extract number out of the file title for further usage

data analysisstring

hi everyone,
i have many files inside a folder. The files have names like 12E.dat, 13.dat, …100.dat i use the following code to load them
files = dir('*.dat');
for k = 1:numel(files)
D = load(files(k).name);
tof = D(:,2)*1000;
...
end
I want to creat an array like E = [12, 13, …, 100] taken out of the title of the file. Is their a way to realize this?
thanks a lot in advance

Best Answer

files = dir('*.dat');
names = {files.name} ; % put the names in a cell array of strings
names = strrep(names,'.dat','') ; % remove extension
Names is now a cell array of strings. If they are all numbers, you can convert them using str2double
values = str2double(names)