How to split string

3 vues (au cours des 30 derniers jours)
Mekala balaji
Mekala balaji le 27 Juin 2019
Modifié(e) : Adam Danz le 1 Juil 2019
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 commentaires
Mekala balaji
Mekala balaji le 27 Juin 2019
yes, cell array.
Adam Danz
Adam Danz le 27 Juin 2019
Ok, good. See the example in my answer below and feel free to follow-up with any problems or questions.

Connectez-vous pour commenter.

Réponse acceptée

Adam Danz
Adam Danz le 27 Juin 2019
Modifié(e) : Adam Danz le 1 Juil 2019
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' }

Plus de réponses (0)

Catégories

En savoir plus sur Data Import and Export dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by