How to erase cell array element with less than three characters

3 Ansichten (letzte 30 Tage)
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 Kommentar
Stephen23
Stephen23 am 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'

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

KSSV
KSSV am 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 Kommentare
Davindra Usov
Davindra Usov am 22 Jun. 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 :)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Cell Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by