How to write an automatic function based on the median of data to form groups of data.
3 次查看(过去 30 天)
显示 更早的评论
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/660165/image.jpeg)
Thanks in advance.
0 个评论
采纳的回答
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
% 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!