Similar to the method to remove unwanted element in a matrix, which is discussed in details in another post (
http://matlabnewbie.blogspot.com/2009/07/matlab-remove-all-unwatned-elements-in.html), the unwanted cell element can be removed from a cell array. The only difference is that the strcmp function should be used to identify where all those unwanted cells are.
The following example shows how to remove the cell 'good' from the cell array a, to be somehow humble.
a=[{'this'},{'is'},{'a'},{'good'},{'matlab'},{'blog'}]; % create a cell array
a=a(~strcmp(a, 'good')) % remove the 'good' cell
Result looks like this:
a =
'this' 'is' 'a' 'matlab' 'blog'
Awesome! Thanks :)
ReplyDeleteYou are welcome! Thanks for visiting.
DeleteMy friend do you know how to do it with a non-string cell array? I'm really confused :s thanks
ReplyDeleteYou can get some latest computer tips, blogging tips and internet tips in the blog TechnTechie.
ReplyDeleteYou could create the cell array slightly more simply using:
ReplyDeletea={'this','is','a','good','matlab','blog'};
And an alternate way of removing matching elements is:
a(strcmp(a,'good')) = [];