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 ?

 Akzeptierte Antwort

dpb
dpb am 24 Jul. 2014

1 Stimme

new= cellfun(@(x) x(1:5),old,'uniformoutput',false);

2 Kommentare

Max Müller
Max Müller am 24 Jul. 2014
Thanks..both ways wokr
dpb
dpb am 24 Jul. 2014
If the pattern isn't fixed length, then regexp is useful; if it is then it's overkill...good to see both

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Azzi Abdelmalek
Azzi Abdelmalek am 24 Jul. 2014

0 Stimmen

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)

Kategorien

Mehr zu Characters and Strings finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 24 Jul. 2014

Kommentiert:

dpb
am 24 Jul. 2014

Community Treasure Hunt

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

Start Hunting!

Translated by