Extract data above threshold from groups

1 回表示 (過去 30 日間)
Elin Jacobs
Elin Jacobs 2022 年 5 月 4 日
編集済み: Elin Jacobs 2022 年 5 月 5 日
I'm trying to extract the y-data that fall into groups (bins) on the x -axis. Ideally, I want to set any y-values that are below the 90th percentile whitin a group to NaN (i.e. I want the end result to be a 6113x1 vector). I have started the following code to bin into groups , but now I am stuck.
load('xydata.mat') %
edges = (min(pp):20:max(pp));
[N, edges, bin] = histcounts(pp, edges);
figure
gscatter(pp,cc,bin)

採用された回答

Chunru
Chunru 2022 年 5 月 5 日
load('xydata.mat')
edges = (min(pp):20:max(pp));
[N, edges, bin] = histcounts(pp, edges);
figure
gscatter(pp,cc,bin)
%whos
y= pp;
ugroups = unique(bin);
for i=1:length(ugroups)
idx = bin == ugroups(i); % data index for the group
if ugroups(i) == 0 % not assigned to any group
y(idx) = nan;
else
ybin = y(idx);
pct = prctile(ybin, 90); % 90 percentile
ybin(ybin>pct) = nan;
y(idx) = ybin;
end
end
[N1, edges, bin] = histcounts(y, edges);
figure
gscatter(pp,cc,bin)
% whos
figure
plot(1:32, N, 'r', 1:32, N1, 'b')
sum(N)
ans = 6105
sum(N1)
ans = 5498
  1 件のコメント
Elin Jacobs
Elin Jacobs 2022 年 5 月 5 日
編集済み: Elin Jacobs 2022 年 5 月 5 日
Thank you very much!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

製品


リリース

R2016a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by