How to parse file name text and save values to variables
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Samantha Plesce
le 2 Nov 2021
Commenté : Samantha Plesce
le 4 Nov 2021
I have several file names that I want to parse through to find if they contain certain words.
ex1) HW_Azcut_y-plane_100-500Hz_V-Vp
ex2) XPOLcut_0.5-300MHz_Hp
I would like to be able to store the upper and lower values of frequencies into separate variables, find whether it is in Vertical (V) or Horizontal (H) , the cut type (Az, XPOL)
0 commentaires
Réponse acceptée
Johnny Himbele
le 2 Nov 2021
str = 'HW_Azcut_y-plane_100-500MHz_V-Vp';
strPart = split(str,"_");
idxCut = contains(strPart,'cut');
strCut = erase(strPart(idxCut),'cut');
if strcmpi(strCut,'Az')
cutType = 'Az';
elseif strcmpi(strCut,'XPOL')
cutType = 'XPOL';
end
idxFreq = contains(strPart,'Hz');
factor = 1.0;
strFreq = strPart(idxFreq);
if contains(strFreq,'kHz')
factor = 1.0e3;
strErase = 'kHz';
elseif contains(strFreq,'MHz')
factor = 1.0e6;
strErase = 'MHz';
elseif contains(strFreq,'GHz')
factor = 1.0e9;
strErase = 'GHz';
end
strFreq = erase(strFreq,strErase);
strFreq = split(strFreq,'-');
for i = 1:length(strFreq)
freq(i) = str2double(strFreq(i))*factor;
end
0 commentaires
Plus de réponses (1)
Sean de Wolski
le 2 Nov 2021
Look at various combinations of the following functions
split
contains
matches
extractBetween, extractBefore, extractAfter
Voir également
Catégories
En savoir plus sur Characters and Strings dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!