Effacer les filtres
Effacer les filtres

I am a MATLAB beginner, I have a function that generates 100 X and Y coordinates for 30 users. X and Y are 30 by 100 matrices. How do I generate the distance between a user and the other 29 users, for each of the 30 users.

1 vue (au cours des 30 derniers jours)
NoUsers = 30; s = 100; alpha = 1.5; [x,y] = levywalkfunc(alpha,s); for m = 1:NoUsers [x(m,:),y(m,:)] = levywalkfunc(alpha,s); end for m = 1:NoUsers activeset = setdiff(1:NoUsers,m); for j = activeset for t= 1:s D(m, s) = sqrt((x(m,s) - x(j,s))^2+(y(m,s) - y(j,s))^2); end end

Réponse acceptée

Giridharan Kumaravelu
Giridharan Kumaravelu le 23 Juil 2018
for m = 1:NoUsers
for j = 1:NoUsers
for t = 1:s
D(m,j,t) = sqrt((x(m,t) - x(j,t))^2+(y(m,t) - y(j,t))^2);
end
end
end
I believe this is what you were trying to do, which outputs a three dimensional vector of distances of the 100 points between users. This could be very inefficient way doing in MATLAB. The power of MATLAB lies in the efficient built-in functions for matrix operations which can run faster than looping statements.
You could try the dist () function.
Note: {}Code button at the top of the editor is a useful tool to type a clean code.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits


Version

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by