Shuffle the rows and calculate the distance
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Image Analyst
le 8 Mai 2021
Modifié(e) : Image Analyst
le 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 commentaires
Voir également
Catégories
En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!