Tuesday, March 24, 2015

Matlab: Remove a cell element from a cell array

Just like the tactic to take away undesirable component in a matrix, which is mentioned in particulars in one other publish (http://matlabnewbie.blogspot.com/2009/07/matlab-take away-all-unwatned-parts-in.html), the undesirable cell factor could be faraway from a cell array. The one distinction is that the strcmp perform ought to be used to determine the place all these undesirable cells are.

The next instance exhibits learn how to take away the cell 'good' from the cell array a, to be by some means humble.

a=['this','is','a','good','matlab','blog'];                 % create a cell array
a=a(~strcmp(a, 'good'))                                                          % take away the 'good' cell

End result seems to be like this:


a = 

    'this'    'is'    'a'    'matlab'    'weblog'

No comments:

Post a Comment