How to erase cell array element with less than three characters
8 views (last 30 days)
Show older comments
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 Comment
Stephen23
on 7 May 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'
Accepted Answer
KSSV
on 7 May 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 Comments
Davindra Usov
on 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 :)
More Answers (0)
See Also
Categories
Find more on Cell Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!