Removing non-unique values and rearranging vectors

点点圈 提交于 2019-12-12 01:13:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!