To determine whether data in Group1 aligns with the expected distribution in Group2 you can use the "pdist2" function to calculate the distance between the data points and use the "find" function for logically identifying the outliers after specifying a certain threshold.
% Example Group1 and Group2 data
Group1 = [7.1, 2.2; 6.9, 2.1; 7.5, 2.5];
Group2 = [7, 2; 8, 3];
% Calculate pairwise distances
distances = pdist2(Group1, Group2);
% Find the closest Group2 element for each Group1 point
[minDistances, closestIndices] = min(distances, [], 2);
% Determine outliers based on a threshold
outlierThreshold = 0.5;
outliers = find(minDistances > outlierThreshold);
% Display results
fprintf('Closest Group2 elements for each Group1 point: [%s]\n', join(string(closestIndices), ','));
fprintf('Outliers: [%s]\n', join(string(outliers), ','));
For determining the elements of Group2 which fall within the ranges specified in Group3, you can use both the "discretize" function or logical indexing.
% Example Group3 ranges
Group3 = {[5, 8; 0, 4], [7, 9; 0, 4]};
% Initialize clusters
clusters = cell(size(Group3));
% Check membership for each Group2 element using logical indexing
for i = 1:length(Group3)
range = Group3{i};
inCluster = Group2(:, 1) >= range(1, 1) & Group2(:, 1) <= range(1, 2) & ...
Group2(:, 2) >= range(2, 1) & Group2(:, 2) <= range(2, 2);
clusters{i} = find(inCluster);
end
% Display cluster assignments
for i = 1:length(clusters)
fprintf('Group3(%d) contains Group2 elements: [%s]\n', i, join(string(clusters{i}), ','));
end
For more information regarding the "pdist2" and "find" functions, refer to the following documentation links: