필터 지우기
필터 지우기

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 (최근 30일)
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

채택된 답변

Giridharan Kumaravelu
Giridharan Kumaravelu 2018년 7월 23일
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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by