find length of a line use 2 dots
Afficher commentaires plus anciens
Hello.. I have code like this
x = [0.2177, 0.6302, 0.9597, 0.6025];
y = [0.4284, 0.7822, 0.5073, 0.1564];
for m = 1:length(x)
for n = 1:length(x)
(n)= sqrt((x(:,n+m) - x(:,n)).^2 + (y(:,n+m) - y(:,n)).^2)
end
end
pjgtot = sum(pjg)
and the result are:
pjg =
0.5434
pjg =
0.5434 0.4291
pjg =
0.5434 0.4291 0.5007
??? Attempted to access x(:,5); index out of
bounds because size(x)=[1,4].
Error in ==> maze_solution at 322
pjg (n)= sqrt((x(:,n+m) - x(:,n)).^2 +
(y(:,n+m) - y(:,n)).^2)
>>
the result is true, that is :
pjg = 0.5434 0.4291 0.5007
but it give some error too.. why it happened .. is there something wrong with my code..?? manual calculations to obtain these results is (in this example, i use x = 0.2177, 0.6302, and y = 0.4284, 0.7822)
pjg = sqrt((0.6302-0.2177)^2 + (0.7822-0.4284)^2)
where is the fault..??
thank you.. :)
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!