Showing posts with label manipulation. Show all posts
Showing posts with label manipulation. Show all posts

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'

Friday, February 22, 2013

Convert a dataset to matrix

For the simplest case when the dataset only contains numbers, this double function can be used to convert a dataset to matrix, or a vector if there is only one variable in the dataset:

m=double(ds)

Monday, November 28, 2011

remove any rows that contains a specific number in Matlab

In this post, I am trying to solve the problem given in the comments of one of the old post.
Here's the problem, if I understand it correctly:

a =

     1     2     3     4     5
     2     3     4   -99     6
     3     4     5     6     7
     4   -99     6     7     8
     5     6     7     8     9

How to remove all the rows that contains the number -99, in this case, the row #2 and #4?

And here's the code I wrote to do this job:

[rows col]=size(a); %count the number of rows and columns of matrix a
j=0; %initialize a counter;
for i=1: rows
    if sum(a(i,:)~=-99)==col; %This determines if the row has -99 or not, if not, do nothing
    else     %shift all of the rest of the rows up one row
        for m=i: rows-1; 
        a(m,:)=a(m+1,:);
        end
        j=j+1; %count how many rows has -99, which equals how many times the rows has been shifted up 
    end
end
b=a((1:rows-j),:); %get rid of the last j rows


The result is:



b =


     1     2     3     4     5
     3     4     5     6     7
     5     6     7     8     9



I hope this can work for you, Winifred. Thanks for your comments!

Thursday, November 17, 2011

How to concatenate two datasets in Matlab?

I wanted to vertically combine two datasets, so I can keep a long file of all the test results. The join function does not work here anymore. Of course this is even not a problem in Excel. However, to make it work in Matlab, it did took me a while to figure it out.

c=cat(1, a, b)


my-alpine and docker-compose.yml

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