find distance between points and select longest 2 lines in matlab

To find the distance between points in matlab, you can use the pdist2 function. Here is an example:

main.m
% Define two sets of points
set1 = [1, 2; 3, 4; 5, 6];
set2 = [2, 3; 4, 5];

% Calculate the distance matrix between the points
dist_matrix = pdist2(set1, set2);

% Display the distance matrix
disp(dist_matrix);
212 chars
10 lines

To select the longest two lines, you can use the sort function to sort the lines by their length, and then select the first two. Here is an example:

main.m
% Define a set of lines as a matrix
lines = [1, 2, 3, 4; 5, 6, 7, 8; 9, 10, 11, 12];

% Calculate the length of each line
line_lengths = sqrt((lines(:, 3) - lines(:, 1)).^2 + (lines(:, 4) - lines(:, 2)).^2);

% Sort the lines by length
[sorted_lengths, sorted_indices] = sort(line_lengths, 'descend');

% Select the longest two lines
longest_lines = lines(sorted_indices(1:2), :);

% Display the longest two lines
disp(longest_lines);
435 chars
15 lines

gistlibby LogSnag