MATLAB Answers

How to write an automatic function based on the median of data to form groups of data.

조회 수: 1(최근 30일)
zhoug zho
zhoug zho 2021년 6월 21일
댓글: zhoug zho 2021년 6월 21일
How to write an automatic function based on the median of data to form groups of data.
as the boxplots are here in this figure, i need to make groups or clusters of data based on median. like once i have median of data, then i need to identify the beginning of a new cluster/group when the median delay increase instead of decresing. and when the median again increases then from that point a new group or cluster will start.
i manually grouped the data based on median, i need to make function like this.
Thanks in advance.

채택된 답변

Adam Danz
Adam Danz 2021년 6월 21일
편집: Adam Danz 2021년 6월 21일
% Create demo data : nxm matrix with 1 box per column
rng('default')
data = rand(100,15) + [1.0 1.3 0.8 0.95 1.02 1.05 1.08 1.2 1.0 1.03 1.06 0.90 0.95 0.80 1.1];
% Compute median of each column
dataMedians = median(data);
% Create boxplot
h = boxplot(data);
% Add group separation lines
groupStart = diff([inf,dataMedians])<0;
groupIdx = find(groupStart);
for i = 1:numel(groupIdx)
xline(groupIdx(i)-.5, 'k--', 'LineWidth',1)
end
% Color the groups
colors = lines(sum(groupStart));
groupID = cumsum(groupStart);
for i = 1:sum(groupStart)
set(h(:,groupID==i), 'Color', colors(i,:))
end
Using boxchart with group separation lines (for color control see demo1, demo2, documentation demo.
% Create demo data : nxm matrix with 1 box per column
rng('default')
data = rand(100,15) + [1.0 1.3 0.8 0.95 1.02 1.05 1.08 1.2 1.0 1.03 1.06 0.90 0.95 0.80 1.1];
% Compute median of each column
dataMedians = median(data);
% Create boxplot
figure()
h = boxchart(data);
% Add group separation lines
groupStart = diff([inf,dataMedians])<0;
groupIdx = find(groupStart);
for i = 1:numel(groupIdx)
xline(groupIdx(i)-.5, 'k--', 'LineWidth',1)
end

추가 답변(0개)

범주

Community Treasure Hunt

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

Start Hunting!

Translated by