How to split string

조회 수: 4 (최근 30일)
Mekala balaji
Mekala balaji 2019년 6월 27일
편집: Adam Danz 2019년 7월 1일
Hi,
I have the below cell array and want to split at common dilimiter of the specified column.
Group Sub_group Name Date Value
Group1 S1Gp11 HATU R2016-06-01_00 1
Group1 S1Gp11 HATU R2016-06-01_01 1
Group2 J1Gp21 LARU R2016-06-02_01 0
I want to split at "_" and retain everything before "_".
Desired Output:
Group Sub_group Name Date Value
Group1 S1Gp11 HATU R2016-06-01 1
Group1 S1Gp11 HATU R2016-06-01 1
Group2 J1Gp21 LARU R2016-06-02 0
  댓글 수: 3
Mekala balaji
Mekala balaji 2019년 6월 27일
yes, cell array.
Adam Danz
Adam Danz 2019년 6월 27일
Ok, good. See the example in my answer below and feel free to follow-up with any problems or questions.

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

채택된 답변

Adam Danz
Adam Danz 2019년 6월 27일
편집: Adam Danz 2019년 7월 1일
c = {'Group' 'Sub_group' 'Name' 'Date' 'Value';
'Group1' 'S1Gp11' 'HATU' 'R2016-06-01_00' '1'
'Group1' 'S1Gp11' 'HATU' 'R2016-06-01_01' '1'};
colIdx = strcmpi(c(1,:),'Date'); % column number of "Date" column
cClean = c; %copy the array if you want to keep the original
cClean(:,colIdx) = regexprep(cClean(:,colIdx),'_.*','');
Result
cClean =
3×5 cell array
{'Group' } {'Sub_group'} {'Name'} {'Date' } {'Value'}
{'Group1'} {'S1Gp11' } {'HATU'} {'R2016-06-01'} {'1' }
{'Group1'} {'S1Gp11' } {'HATU'} {'R2016-06-01'} {'1' }

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by