Filter löschen
Filter löschen

How to find minimal distance during locomotion

1 Ansicht (letzte 30 Tage)
Alex castilla
Alex castilla am 9 Mär. 2018
Kommentiert: Alex castilla am 19 Mär. 2018
Hello,
I would like to find the distance between two points. I have a dataset with 4 columns , the first and second column are the x,y coordinates for the participants locomotion, the third and fourth columns are the X,Y coordinates for the targets (total targets =9, ). I would like to know if the participant reached a target or several targets during de locomotion using the distance. I wrote this function :
function d= distini(x,X,y,Y)
for i=1:length(x)
for ii=1:9
t= sqrt(((X(ii) - x(i)).^2) + ((Y(ii)- y(i)).^2));
d=t'
end
end
end
thanks in advance
  1 Kommentar
Jan
Jan am 10 Mär. 2018
What is your question?
Your t is a scalar, so there is no effect in transposing it.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Jan
Jan am 10 Mär. 2018
Bearbeitet: Jan am 10 Mär. 2018
I'm not sure, what you are asking for. So just a guess:
function d = distini(x,X,y,Y)
d = zeros(numel(X), numel(x));
X = X(:); % If X and Y are not column vectors
Y = Y(:);
for k = 1:numel(x)
d(:, k) = sqrt((X - x(k)) .^ 2 + (Y - y(k)) .^ 2);
end
end
Does this help?
  5 Kommentare
Jan
Jan am 18 Mär. 2018
A = rand(2099, 2);
B = rand(9, 2);
D = zeros(9, 1);
for k = 1:9
dist = (A(:, 1) - B(k, 1))^2 + (A(:, 2) - B(k, 2))^2;
D(k) = sqrt(min(dist));
end
Now D(k) contains the minimal distance of the trajectory in A to B(k).
Alex castilla
Alex castilla am 19 Mär. 2018
Thanks so much

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by