Extracing the part of the string from cell array

조회 수: 1 (최근 30일)
Gopalakrishnan venkatesan
Gopalakrishnan venkatesan 2018년 6월 25일
댓글: Paolo 2018년 6월 25일
I have a cell array a = {'abc__first__element' ; 'def__second__element'; ghi__third__element'}
I want to extract the string after first '__'
My final answer should be a = {'first__element'; 'second__element'; 'third__element'}
How can do this?
Thanks a lot

채택된 답변

Paolo
Paolo 2018년 6월 25일
regexp(a,'(?<=__)(.*)','match')
  댓글 수: 2
Stephen23
Stephen23 2018년 6월 25일
+1 nice and simple. To avoided nested cell arrays in the output use the 'once' option:
regexp(a,'(?<=__)(.*)','match','once')
Paolo
Paolo 2018년 6월 25일
Good point! Would +1 your comment if that was a thing.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by