Complicated Question / String Arrays

3 ビュー (過去 30 日間)
Max Müller
Max Müller 2014 年 7 月 24 日
コメント済み: dpb 2014 年 7 月 24 日
Hey Guys, i have an array of strings which looks like this:
'J_012(105)' 'J_013(106)' 'J_014(107)' 'J_015(2)' J_016(94)' 'J_017(95)'
But I need it to look like this:
'J_012' 'J_013' 'J_014' 'J_015' 'J_016' 'J_017'
So That the ALWAYS the last 4Strings are deleted/kill. Is this possible ?

採用された回答

dpb
dpb 2014 年 7 月 24 日
new= cellfun(@(x) x(1:5),old,'uniformoutput',false);
  2 件のコメント
Max Müller
Max Müller 2014 年 7 月 24 日
Thanks..both ways wokr
dpb
dpb 2014 年 7 月 24 日
If the pattern isn't fixed length, then regexp is useful; if it is then it's overkill...good to see both

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

その他の回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 7 月 24 日
A={'J_012(105)' 'J_013(106)' 'J_014(107)' 'J_015(2)' 'J_016(94)' 'J_017(95)'}
B=cellfun(@(x) x{1} ,regexp(A,'.+(?=\()','match'),'un',0)
  1 件のコメント
Max Müller
Max Müller 2014 年 7 月 24 日
Thanks..both ways work

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

カテゴリ

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