MATLAB: How to seperate the scattered population in three broad groups

scattered population in three broad groups

I would appreciate your help and suggestions. Please find attached the XY plot where the (X,Y) points are broadly separated in three regions ( marked) based on some geochemical anomaly.For any set of data, I can manually separate these three regions 1) High X values with high scatter on the top (High SD) followed by 2) middle region with moderate X values less scatter (SD low) 3) Very low X values , uniform with less scatter ( very low SD). How to separated these three regions by using Matlab and put the marker lines as marked with dashed line? Regards, Sanjib

Best Answer

If you want to manually decide where the partition line is, then this is more or less how you would go about recreating your Excel chart in Matlab, obviously using real data:
% Randomly generated data
x = 1:30;
y = 0.5*x;
y(1:10) = y(1:10).*rand(1,10);
y(11:20) = y(11:20)+4*rand(1,10);
y(21:30) = y(21:30)+8*rand(1,10);
% partition lines data
x1 = [min(x) max(x)]; % x-range for the partition lines
y1 = [4 4]; % dashed black line
y2 = [15 15]; % dashed red line
% main plot
figure
p(1) = plot(x,y);
hold on
p(2) = plot(x1,y1);
p(3) = plot(x1,y2);
title('Chart title')
xlabel('x-axis data')
ylabel('y-axis data')
legend({'Main data' 'partition A' 'partition B'},...
'Location','best')
% set the properties of the lines
% p(1) - main data
set(p(1),...
'LineStyle' ,'-',...
'LineWidth' ,0.5,...
'Color' , [0 0 0],...
'Marker' , '.',...
'MarkerSize' , 12,...
'MarkerFaceColor',[0 0 1],...
'MarkerEdgeColor',[0 0 1]);
% p(2) and p(3) - partition lines COMMON settigs
set([p(2), p(3)],...
'LineStyle','--',...
'LineWidth',0.5);
% p(2) - color
set(p(2),...
'Color', [0 0 0]);
set(p(3),...
'Color', [1 0 0]);
The output: