Cut part of filename using delimiter

13 ビュー (過去 30 日間)
Nik Rocky
Nik Rocky 2020 年 6 月 24 日
コメント済み: Nik Rocky 2020 年 6 月 24 日
Hello,
i have files:
001_m1_60_const_20200611_200515_SNR_5_PLL.mat
001_m1_60_const_20200611_200515_SNR_10_PLL.mat
001_m1_60_const_20200611_200515_SNR_15_PLL.mat
001_m1_60_const_20200611_200515_SNR_20_PLL.mat
001_m1_60_const_20200611_200515_SNR_25_PLL.mat
001_m1_60_const_20200611_200515_SNR_30_PLL.mat
The problem is, sometimes is a dataname longer or shorter, for exemple:
008_m3_m4_m1_m2_ramp_const_20200111_200415_SNR_25_PLL.mat
I need to cut "_SNR_30_PLL" and get just a:
001_m1_60_const_20200611_200515.mat
my code is not dynamic, and works just with special name length:
name_sep = split(name,"_");
sep = '_';
name_join=[name_sep{1,1} sep name_sep{2,1} ...... .mat];
so i have to join all pieces, witout last three.
How it is works?
Thank you!

採用された回答

Kojiro Saito
Kojiro Saito 2020 年 6 月 24 日
If you're using R2016b or later, extractBefore might be a good option.
newStr = extractBefore(name, "_SNR");
name_join = strcat(newStr, ".mat");
  1 件のコメント
Nik Rocky
Nik Rocky 2020 年 6 月 24 日
Thank you very much!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSoftware Development Tools についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by