1 view (last 30 days)

Show older comments

Hello, I am working with a set of 10 xy pairs of points in my data set. I sort the data based on how far apart the 10 points are from each other on my plot. I have a bit of code which allows me to determine which points pass and fail this threshold test, but it reports the numbers individually and I wish to report them as pair based on their index numbers in the matrix A, and the then retain the point in each pair which has the lower index number. For example, if point 1 and point 8 & point 7 and point 10 are too close to each other then, I would like for them to be stored as a pair and then select points 1 and 7 for retention and points 8 and 10 for elimination. I have attached the code I am using to sort them with along witht the data set I am flitering. Thanks for any and all tips.

% CTR Surface Area Simulator

close all;

clear;

clc;

cla;

n = 10; % total number of points

elim_radii = 12;

radii_node = 4;

fontsize = 12;

axis([-100, 100 -100 100]);

% iterations = 3; % total number of loops

% Axis Labels

xlabel('X', 'Fontsize', fontsize);

ylabel('Y', 'Fontsize', fontsize);

title('CTR Surface Area Algorithm', 'Fontsize', fontsize);

hold on

% Plot Outerboundary Circular Plane

x0 = 0;

y0 = 0;

radii_plane = 80;

radii_vein = 4;

center_plane = [x0, y0]; % center point of circular plane

viscircles(center_plane, radii_plane, 'color', 'b');

hold on

%%

% plots center of the plane

plot(x0, y0, '*', 'color', 'k', 'markersize', 12);

viscircles(center_plane, radii_vein, 'color', 'k');

hold on

%%

% Hormone Seeds Gen 2 Calculations

% Create 2nd Set of Randoom Points to be Plotted

CTR_HStoSA1076_2 = importdata('CTR_HStoSA1076_gen2.txt');

A = zeros(n, 2); % Preallocation for A

t = CTR_HStoSA1076_2.data(:, 1);

r = CTR_HStoSA1076_2.data(:, 2);

x = CTR_HStoSA1076_2.data(:, 3);

y = CTR_HStoSA1076_2.data(:, 4);

A = [x, y]; % stores random points generated

% Plots n random points

CTR_graph2 = plot(x, y, '.', 'color', 'g', 'Markersize', 12);

axis square;

CTR_circles2 = gobjects(n, 1);

% plots circles centered around the randomly generated points

for i = 1:n

centers_node2 = [x(i), y(i)];

CTR_circles2(i,:) = viscircles(centers_node2, radii_node, 'color', 'g');

hold on

end

HS_gen2 = A;

%%

% HS_HS Elimination Test Gen 2

% draw exlcusion range circles b/w hormone seeds and hormone seeds for HS gen 2

elim_circles2 = gobjects(n, 1);

for i = 1:n

centers_node2 = [x(i), y(i)];

elim_circles2(i) = viscircles(centers_node2, elim_radii, 'color', 'k', 'linestyle', '--');

end

%%

% HS-HS Gen 2 Elimination HS gen 2 vs HS gen 2

elim_dist4 = nan(numel(x)); % creates nan matrix and places nans on the diagonal after distance calculation

HS_HS_threshold = 12;

for i = 1:n

for j = 1:(i-1) % distance symmetric (l(i1,i2) == l(i2,i1))

elim_dist4(i,j) = sqrt((x(i)-x(j)).^2 + (y(i)-y(j)).^2);

elim_dist4(j,i) = elim_dist4(i,j);

end

end

% find the points that have its nearest neighbor further away than HS_HS_threshold:

i2keepHS_HS2 = find(min(elim_dist4)> HS_HS_threshold);

i2notkeepHS_HS2 = find(min(elim_dist4)< HS_HS_threshold);

keep_x4 = x(i2keepHS_HS2);

keep_y4 = y(i2keepHS_HS2);

x_close_neighbors4 = x;

y_close_neighbors4 = y;

x_close_neighbors4(i2keepHS_HS2) = [];

y_close_neighbors4(i2keepHS_HS2) = [];

G = [keep_x4, keep_y4];

experiment = [x_close_neighbors4, y_close_neighbors4];

Adam Danz
on 11 Nov 2019

Edited: Adam Danz
on 12 Nov 2019

I think you're looking for....

% Coordinates you're keeping

keepCoordinates = A(i2keepHS_HS2, :);

% Coordinates you're not keeping

tossCorrdinates = A(i2notkeepHS_HS2, :);

Idea #2 (added after the initial discussion below).

When you create the distance matrix, you only need the upper or lower triangle of the matrix. I think the problem is solved by...

for i = 1:n

for j = 1:(i-1) % distance symmetric (l(i1,i2) == l(i2,i1))

elim_dist4(i,j) = sqrt((x(i)-x(j)).^2 + (y(i)-y(j)).^2);

% elim_dist4(j,i) = elim_dist4(i,j); % REMOVE THIS

end

end

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

Start Hunting!