Hi Guys!
I am trying to split a numberic sting in cell array data. but unable to do it.
a = {'c\datat\pic\res\000-774'; '\c\datat\pic\res\152-7987';}
need output like
a1 = ('c\datat\pic\res\';'c\datat\pic\res\ ')
a2 = ('000-774';'125-7957')
can anyone help me to solve.
thanks in adavance!!

댓글 수: 5

KSSV
KSSV 2020년 4월 24일
Read about regexp.
Tommy
Tommy 2020년 4월 24일
Or possibly fileparts? Based on your example
dpb
dpb 2020년 4월 24일
편집: dpb 2020년 4월 24일
@Tommy is spot on...
> [a1,a2]=cellfun(@fileparts,a,'UniformOutput',false)
a1 =
2×1 cell array
{'c\datat\pic\res' }
{'\c\datat\pic\res'}
a2 =
2×1 cell array
{'000-774' }
{'152-7987'}
>>
Given they're file names by inspection, just lacking the optional extension.
Suggest move to an Answer so OP can Accept and go on to bigger and better things... :)
Tommy
Tommy 2020년 4월 24일
Happily, though seems to me you did all the work!
dpb
dpb 2020년 4월 24일
You had the bright (and to me right) idea, though...the rest is a oneliner...

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

 채택된 답변

Tommy
Tommy 2020년 4월 24일
편집: Tommy 2020년 4월 24일

1 개 추천

Use fileparts and cellfun. Code courtesy of @dpb:
>> a = {'c\datat\pic\res\000-774'; '\c\datat\pic\res\152-7987'};
[a1,a2]=cellfun(@fileparts,a,'UniformOutput',false)
a1 =
2×1 cell array
{'c\datat\pic\res' }
{'\c\datat\pic\res'}
a2 =
2×1 cell array
{'000-774' }
{'152-7987'}

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

질문:

2020년 4월 24일

편집:

2020년 4월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by