reading text files based on specific sub-string values.

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

 採用された回答

dpb
dpb 2021 年 7 月 14 日

0 投票

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 件のコメント

Ioannis Matthaiou
Ioannis Matthaiou 2021 年 7 月 14 日
thank you.
Ioannis Matthaiou
Ioannis Matthaiou 2021 年 7 月 14 日
just as a note: I also tried solving this using "extractBetween" and works great.
dpb
dpb 2021 年 7 月 14 日
That also would work, yes...many ways to deal with the proverbial cat... :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCharacters and Strings についてさらに検索

製品

リリース

R2021a

質問済み:

2021 年 7 月 14 日

コメント済み:

dpb
2021 年 7 月 14 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by