Search code examples
matlabsortingastronomylarge-data

Removing non-unique values and rearranging vectors


I worked with Sloan Digital Sky Survey (SDSS) data, and got a final data product of this file. The first column is of wLength (wavlength) and second is of flux.

Storing the zeros in zero_F variable zero_F = find(a==0), I removed them from both columns using wLength(zero_F)=[]; and flux(zero_F)=[];. I want to plot wLength vs flux, flux is dependent on wLength but wLength contains values which are non-unique.

How can I get indices of non-unique values in data so that I can remove the corresponding indices from both wLength and flux to make the arrays of same size and plot them. Also, since issorted(wLength) returned 0 that'd mean that wLength isn't sorted out, but sorting it out will definitely change the correspondence of it's values with flux, how can I sort flux based on wLength values.

I read about sorting x vs y here and here but I quite didn't get the answers.


Solution

  • You could try something like this:

    % Get unique values from wLength
    [wLengthUn, iUn, ~] = unique(wLength);
    fluxUn = flux(iUn);
    
    % Sort the arrays, if needed
    [wLengthSrt, iSrt] = sort(wLengthUn);
    fluxSrt = fluxUn(iSrt);
    
    % Plot data
    plot(fluxSrt, wLengthSrt)