How to parse file name text and save values to variables

13 ビュー (過去 30 日間)
Samantha Plesce
Samantha Plesce 2021 年 11 月 2 日
コメント済み: Samantha Plesce 2021 年 11 月 4 日
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)

採用された回答

Johnny Himbele
Johnny Himbele 2021 年 11 月 2 日
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

その他の回答 (1 件)

Sean de Wolski
Sean de Wolski 2021 年 11 月 2 日
Look at various combinations of the following functions
split
contains
matches
extractBetween, extractBefore, extractAfter

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by