How can I group positive peaks in groups by their similar values ?

조회 수: 2 (최근 30일)
Heirleking
Heirleking 2022년 3월 21일
댓글: Image Analyst 2022년 3월 22일
So I have both positive and negative peaks for any given signal. I am interested in grouping them into positive and negative
pks_max =[
6.8285
6.0007
13.4501
13.4501
22.5547
23.3825
32.0733
31.6596
48.6273
49.4551
66.4228
85.4598
85.4598];
Here is my code for positive peaks, given that there is a same amount of positives as negatives, I could use the same code. This code worked when there were a same amount of values for each group, but it doesn't for my new case
% Get distance of every element to every other element.
distances_max = pdist2(pks_max,pks_max);
% Find out which pairs are within 1 of each other.
within2_max = distances_max > 0 & distances_max < 5;
% Erase upper triangle to get rid of redundancy
numElements_max = numel(pks_max);
j_max = logical(triu(ones(numElements_max, numElements_max), 0));
within2_max(j_max) = 0;
% Label each group with an ID number.
[labeledGroups_max, numGroups_max] = bwlabel(within2_max);
% Put each group into a cell array
for k = 1 : numGroups_max
[rows_max, columns_max] = find(labeledGroups_max == k);
indexes_max = unique([rows_max, columns_max]);
groups_max{k} = pks_max(indexes_max);
end
celldisp(groups_max); % Display the results in the command window.
  댓글 수: 5
Heirleking
Heirleking 2022년 3월 22일
I did not show the negative peaks it is a signal. All I need to know is how to group these array of numbers
Image Analyst
Image Analyst 2022년 3월 22일
I see you accepted David's reply below so it appears that what you were really after was the histogram, you just didn't know the name of the function, and instead used words like peaks and groups. Well, glad you learned a new term and that David solved it for you. And thanks in advance for Accepting his answer to award him reputation points. Of course I suspect he has a prerelease version of the Mind Reading Toolbox.

댓글을 달려면 로그인하십시오.

답변 (1개)

David Hill
David Hill 2022년 3월 22일
[~,~,bins]=histcounts(pks_max,[0 10 20 30 40 50 60 70 80 90]);%or whatever bin edges you want
u=unique(bins);
for k=1:numel(u)
c{k}=pks_max(bins==u(k));%puts groups into different cell elements
end

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by