Shuffle the rows and calculate the distance
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I wrote this code
m=input('Enter Number of rows: ');
n=input('Enter Number of Columns: ');
p = 3 ;
R = [0 10;20 30 ;50 60] ;
A = zeros(m,n) ;
for i = 1:p
idx = (i-1)*m/p+(1:m/p) ;
A(idx,:) = (R(i,2)-R(i,1))*rand(m/p,n)+R(i,1) ;
end
disp(A)
Then, by shuffling all rows (for example, row 1 will be the 10th row in the new matrix, or row 1 will be randomly moved to be the last row in the new matrix), each row will be distances with all other rows, and the distances between rows will be calculated for each respective row. it will be calculated according to the Euclidean relation to match the other row corresponding to it. After calculating the distance between each row and another row, the distance between them should be written in a new matrix. Thus, the distance results for all lines will be obtained. Finally, rows that are in the same group with each other, depending on their distance, will be displayed in a list.
I don't know how to do the last part. Can anyone help me please?
0 Kommentare
Antworten (1)
Image Analyst
am 8 Mai 2021
Bearbeitet: Image Analyst
am 8 Mai 2021
Not exactly sure what you're asking but you can use pdist2() to compute the distance of every x,y coordinate point in a list to every other point in the list:
xy1 = rand(5, 2) % 5 (x,y) coordinates
distanceMatrix1 = pdist2(xy1, xy1)
% Scramble
newOrder = randperm(size(xy1, 1));
xy2 = xy1(newOrder, :)
distanceMatrix2 = pdist2(xy2, xy2)
0 Kommentare
Siehe auch
Kategorien
Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!