How to modify a list of filenames in a specific way?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Amanda
am 15 Dez. 2020
Kommentiert: Amanda
am 15 Dez. 2020
Dear Matlab community,
I have a fairly simple question for you experts. I'd like make a column taking just the first part of a file name (string):
e.g. This is what I have
names =
"vul1_4_9.txt"
"bat1_1_1.txt"
"chy1_1_16.txt"
"chy1_1_17.txt"
"g6_1_18.txt"
"stcv1_1_1.txt"
"ser1_3_4.txt"
And I'd like to have instead a column just with the names before the first "_" :
names=
"vul1"
"bat1"
"chy1"
"chy1"
"g6"
"stcv1"
"ser1"
So far, I was able to "substract" the ".txt" part of the file name using the following loop:
names_n = length(names)
for id = 1:names_n
[~, f,ext] = fileparts(names(id));
rename = strcat(f - '_*_*') ;
names_new = [names_new;rename]
end
Obtaining this output:
names_new=
"vul1_4_9"
"bat1_1_1"
"chy1_1_16"
"chy1_1_17"
"g6_1_18"
"stcv1_1_1"
"ser1_3_4"
How should I proceed?
Akzeptierte Antwort
Stephen23
am 15 Dez. 2020
S = ["vul1_4_9.txt"
"bat1_1_1.txt"
"chy1_1_16.txt"
"chy1_1_17.txt"
"g6_1_18.txt"
"stcv1_1_1.txt"
"ser1_3_4.txt"];
Z = extractBefore(S,'_')
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Standard File Formats 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!