フィルターのクリア

how to compare last n characters of many strings in matlab?

4 ビュー (過去 30 日間)
Tejaswini Ramesh
Tejaswini Ramesh 2016 年 7 月 29 日
編集済み: Stephen23 2016 年 7 月 29 日
I have a huge number strings stored in cell named 'b'. some names of the signals inside this cell looks like this 'PECCalc_tqElFil2_VW_173', 'PECCtl_bDampCtl_VW_173', 'PECCtl_uDstRipplNrm_VW_171', 'PEC_kWaaDkMEoacAcF33ry86TG5B0BRjIXWbgnK1vt1D2Gc_171', 'time_152', 'time_173',
then I use string compare to get only signals starting with the name PEC using the following.
matcontent = load('w50_2_2.mat');
usefield = strncmpi(fieldnames(matcontent),'PEC',3);
b = fieldnames(matcontent);
matcontent_cell = struct2cell(matcontent);
selectedvariables = matcontent_cell(usefield);
so selectedvariables has all the signals starting only with PEC.
Similarly I want to filter out all the signals ending with _173. How do I do this? How can I use string compare to compare last n characters and segregate those signals? the length of these signals also vary. Please help me! Thanks in advance.

採用された回答

Stephen23
Stephen23 2016 年 7 月 29 日
編集済み: Stephen23 2016 年 7 月 29 日
Use regexp, you can wrap it in a cellfun call to get the indices:
C = {...
'PECCalc_tqElFil2_VW_173'
'PECCtl_bDampCtl_VW_173'
'PECCtl_uDstRipplNrm_VW_171'
'PEC_kWaaDkMEoacAcF33ry86TG5B0BRjIXWbgnK1vt1D2Gc_171'
'time_152'
'time_173'
}
fun = @(str,pat)~cellfun('isempty',regexp(str,pat,'once'));
idxPEC = fun(C,'^PEC')
idx173 = fun(C,'\_173$')
returns these indices:
idxPEC =
1
1
1
1
0
0
idx173 =
1
1
0
0
0
1
  3 件のコメント
Tejaswini Ramesh
Tejaswini Ramesh 2016 年 7 月 29 日
please also tell me how to get all the names of the signals when idx173 or idxPEC value is 1. Thank you!
Stephen23
Stephen23 2016 年 7 月 29 日
編集済み: Stephen23 2016 年 7 月 29 日
Using very basic array indexing:
C(idxPEC | idx173)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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