MATLAB: How to pick a set of data close to one another


I would like to automate the process of choosing the data series that are withing a range close to the overall data line (black line in figure). Is there a way to do this in MATLAB? Below is the picture of my 21 data series and I am only interested in the series that are close to it. The process I have to do to pick them out is trial-and-error, but I would like to develop a code that could find the series that are within 2 orders of magnitude at any given point of the overall. Any suggestions?

Best Answer

  • Is the reference fixed/known a priori, computed from the overall dataset...???
    Presuming the former above and is xref, and other data is array x, the "deadahead" way would be something like:
    dist=100; % difference limit
    [r,c]=size(x); % I'll presume data are by column; transpose or flip logic if not
    ix=false(c,1); % none satisfied yet...just preallocated, will write in loop
    for i=1:c
    d=abs(x(:,i)-xref); % the point-by-point differences
    ix(i)=(min(d)<=dist); % logical vector of those within
    xsave=x(:,ix); % save ones inside distance
    Actually, it became clear it's easy enough w/o the loop, too...
    d=abs(x-xref); % relies on automagic vector expansion (I think this works, haven't learned all the nuances yet)