CleanData.m 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. function cleanx = CleanData(x, rnge, choice, epsilon);
  2. %CLEANDATA
  3. % Usage:
  4. % cleanx = CleanData(x, rnge, choice, epsilon);
  5. %
  6. % This function will take in a data set x, a specific portion of that data,
  7. % rnge, and look for any points below (choice = 'below') or above (
  8. % (choice = 'above') the threshold epsilon. It will then get rid of those
  9. % points and create linearly extrapolated points in their place. It
  10. % returns the cleaned data set cleanx.
  11. %
  12. % Note: This function is to be used ONLY when the user knows for a fact that
  13. % spurious points exist in the data set. It is not very automatic, but
  14. % assures that only KNOWN false points will be removed from the set. In
  15. % order to use this, one must look at a plot of the data to determine the
  16. % portion to look at and the threshold to set.
  17. % Written by Dan Valente
  18. % 10 November 2006
  19. cleanx = x;
  20. dirtyx = x(rnge);
  21. if (strcmp(choice, 'below'))
  22. goodpoints = find(dirtyx > epsilon);
  23. elseif (strcmp(choice, 'above'))
  24. goodpoints = find(dirtyx < epsilon);
  25. end
  26. goodpoints = goodpoints + rnge(1) - 1;
  27. for i = 1:(length(goodpoints)-1)
  28. if ((goodpoints(i+1)-goodpoints(i)) ~= 1)
  29. xf = x(goodpoints(i+1));
  30. xs = x(goodpoints(i));
  31. m = (xf-xs)/(goodpoints(i+1)-goodpoints(i));
  32. count = goodpoints(i);
  33. while count < goodpoints(i+1)
  34. cleanx(count) = m*(count-goodpoints(i))+xs;
  35. count = count+1;
  36. end
  37. end
  38. end
  39. return;