I have a cell array containing double arrays like:
x = {[4,1] [4,3] [1,1] [2,3] [2,1]};
I would like to check if [1,1] is contained in the cell array and if so, delete it. I get it done like this:
x(find(cellfun(@all,cellfun(@(x)x==[1,1],x(:),'UniformOutput', false))==1)) = []
Seems overy complicated though, any suggestions for simplification? thanks in advance!
Without using cellfun, one can use ismember to detect the matching rows and remove them -
x(ismember(vertcat(x{:}),[1 1],'rows'))=[]
Basically the same code you used, but removing everything unnecessary. You don't need to apply cellfun twice to apply two nested functions. Pass the nested function instead.
x(cellfun(@(x)all(x==[1,1]),x)=[]
Besides this, take a look at "logical indexing", you don't need find in such cases.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With