How to erase cell array element with less than three characters

9 vues (au cours des 30 derniers jours)
Damien Williams
Damien Williams le 7 Mai 2019
Commenté : Davindra Usov le 22 Juin 2022
If i have a function that accepts a string of characters eg('cgugcaguca') and i use
cellArr = regexp(mRNA, sprintf('\\w{1,%d}',3),'match');
to arrange the string into a cell array grouped in threes, how do i erase any elements with less than three characters.
eg {'cgu'} {'gca'} {'guc'} {'a'} , i want to erase the cell with 1 character.
  1 commentaire
Stephen23
Stephen23 le 7 Mai 2019
Just specify the regular expression to only return groups of that number:
>> mRNA = 'cgugcaguca';
>> regexp(mRNA,sprintf('\\w{%d}',3),'match')
ans =
'cgu' 'gca' 'guc'

Connectez-vous pour commenter.

Réponse acceptée

KSSV
KSSV le 7 Mai 2019
C = [{'cgu'} {'gca'} {'guc'} {'a'}] ;
L = cellfun(@length,C) ; % GEt length of each cell array
C(L<3) = [] % Remove cell's whose length is less than 3
  2 commentaires
Damien Williams
Damien Williams le 7 Mai 2019
Perfect, thankyou.
Davindra Usov
Davindra Usov le 22 Juin 2022
Hi, do you happen to know how I can remove all string/chars from a 4x10 cell array where each cell in that array contains a 40x1 column vector? (so as you can see, it's nested). Thank you :)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Cell Arrays 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