how to define the coordinate of the last element of one matrix 2*n?
Afficher commentaires plus anciens
i generate n number of nodes in matlab and i wanted it show the x and y cordinate of each node in 2*n matrix. but my question is how can i define the last element of the matrix to find distance between last node and second last node for example.any one can help me with that?
while size<n
if sqrt((N(1,size)-N())^2+(N(2,size)-N())^2)<step
Reach=1; ReachG=size; break
end
Réponses (2)
Star Strider
le 23 Avr 2015
If I understand your Question correctly, to get the distance between the last and the next-to-last elements in your (2xn) matrix, do this:
len = 10;
N = rand(2,len);
Last = N(:,end);
Next_to_Last = N(:,end-1);
Dist = hypot(Last(1)-Next_to_Last(1), Last(2)-Next_to_Last(2));
4 commentaires
amina shafanejad
le 23 Avr 2015
Star Strider
le 23 Avr 2015
If you have two matrices, ‘M’ and ‘N’, and you want to find the distance between the last elements in each one, this would work:
Dist = hypot(M(1,end)-N(1,end), M(2,end)-N(2,end));
amina shafanejad
le 23 Avr 2015
Star Strider
le 23 Avr 2015
My pleasure!
Image Analyst
le 23 Avr 2015
0 votes
The last element (the lower right one) of N is N(end, end).
DON'T USE SIZE AS THE NAME OF A VARIABLE SINCE IT'S THE NAME OF A BUILT-IN FUNCTION.
1 commentaire
amina shafanejad
le 23 Avr 2015
Catégories
En savoir plus sur Operators and Elementary Operations 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!