Search code examples
matlabdata-cleaning

Problem looking at data between 0 and -1


I'm trying to write a program that cleans data, using Matlab. This program takes in the max and min that the data can be, and throws out data that is less than the min or greater than the max. There looks like a small issue with the cleaning part. This case ONLY happens when the minimum range of the variable being checked is 0. If this is the case, for one reason or another, the program won't throw away data points that are between 0 and -1. I've been trying to fix this for some time now, and noticed that this is the only case where this happens, and if you try to run a SQL query selecting data that is < 0, it will leave out data between 0 and -1, so effectively the same error as what's happening to me. Wondering if anyone might recognize this and know what it could be.


Solution

  • I would write such a function as:

    function data = cleanseData(data, limits)
        limits = sort(limits);
        data = data( limits(1) <= data & data <= limits(2) );
    end
    

    an example usage:

    a = rand(100,1)*10;
    
    b = cleanseData(a, [-2 5]);
    c = cleanseData(a, [0 -1]);