reading text files based on specific sub-string values.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Ioannis Matthaiou
am 14 Jul. 2021
Kommentiert: dpb
am 14 Jul. 2021
Hello,
I have several text files with the following format: "mmAAnn.txt". I read all the file names in Matlab without a problem. Now, I want to read each text file separately based on the value of "nn" within that filename's string. For instance, I want to decide to read and write in a variable only those filenames with nn=03. How do I do that?
Thank you,
Yiannis
0 Kommentare
Akzeptierte Antwort
dpb
am 14 Jul. 2021
nWant=3;
wildCardName=sprintf('*%02d*.txt',nWant);
d=dir(wildCardName);
Unfortunately, the MATLAB implementation of dir() only recognizes the asterisk as the wildcard symbol; if need more finesse than it either use regular expressions over the collection of names returned with more general form as above or I often will use the OS more powerful facility instead.
3 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu File Operations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!