delete or keep special rows in a cell array based on specific column values
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Shima Asaadi
le 3 Avr 2016
Commenté : Shima Asaadi
le 3 Avr 2016
I have a cell array with 2 columns. first column is array of strings, and second is numeric values. I would like to delete the rows in which the first column does not contain \w & \s at all using reqexprep. example of cell array:
'summits,' '-1'
'.' ' 3'
'greenhouse' ' 0'
'hello world' '-2'
'abandoned' '-2'
But, I have 2 problems:
- Item two how to delete the whole row which satisfies the condition, like the second row in example which contains '.' in the first column,
- how to keep a row which just have additional "," in the first column, like the first row in example(I mean that I want to delete ',' and keep 'summits' and its row)! It's a bit complicated!!
I would appreciate any help,
Thank you in advance
0 commentaires
Réponse acceptée
Azzi Abdelmalek
le 3 Avr 2016
A={'summits,' '-1'
'.' ' 3'
'greenhouse' ' 0'
'hello world' '-2'
'abandoned' '-2'}
d=cellfun(@(x) regexprep(x,'[,\.]',''),A(:,1),'un',0)
idx=cellfun(@isempty,d)
A(:,1)=d
A(idx,:)=[]
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur MATLAB Report Generator 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!