Effacer les filtres
Effacer les filtres

Distance formula using while loop

2 vues (au cours des 30 derniers jours)
PetronasAMG le 2 Fév 2018
Modifié(e) : Jan le 4 Fév 2018
so i given a data file, I was able to call in these values into Matlab input
these cells are empty because user chooses what values to input I have to call out 5 values for each column fo i (Xa,Ya,Xb,Yb, and t) so will using
while i <= 8
Di = sqrt((Xb-Xa)^2+(Yb-Ya)^2))
will this code give me D1 to D8? also how would I be able to multiple each t(i) into to corresponding Dis???

Réponse acceptée

Jan le 4 Fév 2018
Modifié(e) : Jan le 4 Fév 2018
Do not create a set of variables called "D1, D2, ...". See
and with much more details:
This is more efficient (posted by Youssef already):
D = sqrt((Xb - Xa) .^ 2 + (Yb - Ya) .^ 2))
Then use D(2), D(2), ... instead of D1, D2, ...

Plus de réponses (1)

Youssef  Khmou
Youssef Khmou le 2 Fév 2018
In the given formulae, are the variables vectors? if it is the case, then you need to use index in the loop for each variable to select the ith value at ith iteration:
while ii<=8
in compact form you can directly compute the distance using element wise operation:
to multiply each value of D with its corresonding value of t use the compact form:


En savoir plus sur Logical 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!

Translated by