问题
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.
回答1:
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)
来源:https://stackoverflow.com/questions/37948031/removing-non-unique-values-and-rearranging-vectors