Thursday, February 28, 2013

Matlab: Remove a cell element from a cell array

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'

5 comments:

  1. My friend do you know how to do it with a non-string cell array? I'm really confused :s thanks

    ReplyDelete
  2. You can get some latest computer tips, blogging tips and internet tips in the blog TechnTechie.

    ReplyDelete
  3. You could create the cell array slightly more simply using:
    a={'this','is','a','good','matlab','blog'};

    And an alternate way of removing matching elements is:
    a(strcmp(a,'good')) = [];

    ReplyDelete

Any comments?

my-alpine and docker-compose.yml

 ``` version: '1' services:     man:       build: .       image: my-alpine:latest   ```  Dockerfile: ``` FROM alpine:latest ENV PYTH...