extract number out of the file title for further usage
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Akzeptierte Antwort
Jos (10584)
am 28 Nov. 2013
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)
0 Kommentare
Weitere Antworten (2)
eFKa
am 28 Nov. 2013
4 Kommentare
Image Analyst
am 28 Nov. 2013
Very good point (that I overlooked). Sometimes things like that will slip by and you'll only realize it when you get an angry email from a user about how your code does not work. Like they say in software development "It's hard to make code idiotproof because idiots are so ingenious." But perhaps the 12E was just a typo - who knows? But my first assumption is that the user meant what he said.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!