Assign a part of file name to a variable

5 ビュー (過去 30 日間)
Nitish Reddy Kotkur
Nitish Reddy Kotkur 2019 年 10 月 20 日
回答済み: dpb 2019 年 10 月 20 日
myfolderinfo = dir('some_random_folder') ;
N = length(myfolderinfo) ;
for i = 3:N
thisfile = myfolderinfo(i).name
some_random_folder contains text files with names 5_5.txt,6_6.txt...50_50txt,50_51.txt
now i want to assign the value after underscore to a variable m. such as for file 5_5.txt then m=5 and for file 50_51.txt then m=51
how can i assign those values to m

採用された回答

dpb
dpb 2019 年 10 月 20 日
m=str2num(char(extractBetween(myfolderinfo(i).name,'_','.')));

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB Report Generator についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by