- MAF is in the base filename
- MAF is NOT in the base filename
Help with regexp of varying filenames
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I am sorting through files, trying to extract files using naming attributes.
The most common filename looks like this one with various letters/numbers after the second MESA:
'E:/MESA/IMAGES/Exam1/8015872/010612091858/images/MESA..._8015872_20010120_145658'
But there are some expections that I need to account for like (Notice the ...MAF and MESA...MAF):
'E:/MESA/IMAGES/Exam1/8015872/010612091858/images/...MAF_8015872_20010120_145658'
'E:/MESA/IMAGES/Exam1/8015872/010612091858/images/MESA...MAF_8015872_20010120_145658'
The first path works with the code below, but the second path causes problems.
startIndex = regexp(cur_study_path,'MESA');
studyName = cur_study_path( max(startIndex): end);
Is there anyway to default to:
startIndex = regexp(cur_study_path,'MAF')
when the first path isn't present, without including path names like the third path?
3 Kommentare
Cris LaPierre
am 27 Feb. 2021
Bearbeitet: Cris LaPierre
am 27 Feb. 2021
And pleaes provide the full pathnames. It's hard to propose a solution for the exceptions when we don't know all the details.
Image Analyst
am 27 Feb. 2021
Do you perhaps want to do something like this
filename = strrep(filename, 'MAF', ''); % Remove MAF from filename.
or this;
for k = 1 : numberOfFiles
thisFileName = whatever % Get filename somehow...
if contains(thisFileName, 'MAF', 'IgnoreCase', true)
continue; % Skip files with MAF in the name.
end
% Else process files with no MAF in the name.
end
Antworten (1)
Cris LaPierre
am 27 Feb. 2021
Perform 2 checks, one for MESA, one for MAF. They use max on the combined result.
% Case 1
cur_study_path='E:/MESA/IMAGES/Exam1/8015872/010612091858/images/MESA..._8015872_20010120_145658'
siMESA = regexp(cur_study_path,'MESA');
siMAF = regexp(cur_study_path,'MAF');
studyName = cur_study_path( max([siMESA, siMAF]): end)
% Case 2
cur_study_path='E:/MESA/IMAGES/Exam1/8015872/010612091858/images/...MAF_8015872_20010120_145658';
siMESA = regexp(cur_study_path,'MESA');
siMAF = regexp(cur_study_path,'MAF');
studyName = cur_study_path( max([siMESA, siMAF]): end)
% Case 3
cur_study_path='E:/MESA/IMAGES/Exam1/8015872/010612091858/images/MESA...MAF_8015872_20010120_145658';
siMESA = regexp(cur_study_path,'MESA');
siMAF = regexp(cur_study_path,'MAF');
studyName = cur_study_path( max([siMESA, siMAF]): end)
0 Kommentare
Siehe auch
Kategorien
Mehr zu Logical 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!