Thursday, July 23, 2009

Matlab: Remove all the unwatned elements in matrix

Today I just got a big set of data, the record of ozone level for one year. When the data is bad or there is no data for a certain point of time , they just use a 999. So I want to remover all of the 999s in this matrix.

If use Excel, that's easy- Find and Replace. In matlab, what I did is this:

Matrix=Matrix(Matrix ~=999)

Here's a simpler example:

a=[1 2 3 4 5 6 7 8 9 ];
b=a(a~=4);
->
b=[1 2 3 5 6 7 8 9]

16 comments:

  1. What if we would like to do the same for a 2D matrix where the elements to be deleted are present in another vector?

    ReplyDelete
  2. ?? I don't quite understand your problem.

    ReplyDelete
  3. I have a data for series of all longitudes and latitudes and mangetic latitudes on a file but I have to select the data to plot the data for magnetic latitude for 0 and 10 degree for geographic longitude of 20W-40W and latitude 1- 20S. How can I do for it?
    anyone suggest me with coding.
    THanks,
    Np

    ReplyDelete
  4. Hello NPC,

    I don't really get your questions, sorry. So I have to guess what your problem is. Could you use three layers of if/then command?

    Or if the data set is not too big, maybe you can manually delete those points that you don't need to plot?

    ReplyDelete
  5. I think Pranav Jindal's question is what if there are more than one column. I also want to know what if i have five columns and each column may have the number (say, -99) I don't want. How to do it if that row contains -99 no matter on which column, I want to exclude that whole row?
    Many thanks.

    ReplyDelete
  6. Hello Winifred and NPC, I had a new post on this topic. Please check my latest post here:

    http://matlabnewbie.blogspot.com/2011/11/remove-any-rows-that-contains-specific.html

    I hope this is helpful to you two.

    ReplyDelete
  7. Hi All,

    I am having a big matrix of dimension 36000x7 and I want to delete every 2nd row of this matrix so that finally I am left with a matrix with 18000x7 dim . I don't know how to go about it. I can do the same by extracting one column at a time but that would be time consuming as there are 7 columns and also I have 336 matrices. If I will get to know how to do it for 1 matrix then I will do it for the other ones also. Please help me.......

    ReplyDelete
  8. I think this code can it. I assumed your original matrix is a.

    for i=1:18000
    b(i,:)=a(2*i-1,:)
    end

    Good luck!

    ReplyDelete
  9. Thanks for your help.....But some how it is not working.......

    ReplyDelete
  10. for i=1:18000
    b(:,i)=a(:,2*i-1)
    end

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

    ReplyDelete
  12. Thank you for the example. Here's my problem. I have a dataset of X and Y column for which X value there is a corresponding Y value.
    I need to exclude the rows of X values that are outliers so Y values get removed as well.
    I have identified the values that need to be excluded. Stored as an array in a double form.
    Say the values are stored under 'out'.
    trial=X(X~='out');
    Undefined function 'ne' for input arguments of type 'dataset'.
    But I am assuming the corresponding values of Y for those X values won't be removed.

    ReplyDelete
  13. I hv a 2 D matrix= A=[0 0 1 0 0 2;1 0 1 1 0 0 3]

    nad convert it int B=[0 1 2;1 1 3] removing zeros in adjacent rows

    ReplyDelete

Any comments?

my-alpine and docker-compose.yml

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