필터 지우기
필터 지우기

how to define the coordinate of the last element of one matrix 2*n?

조회 수: 1 (최근 30일)
amina shafanejad
amina shafanejad 2015년 4월 23일
댓글: Star Strider 2015년 4월 23일
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

답변 (2개)

Star Strider
Star Strider 2015년 4월 23일
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

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2015년 4월 23일
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
amina shafanejad
amina shafanejad 2015년 4월 23일
you are right in this case if there is no value for size can u tell me how can i define the last element of the matrix ?

댓글을 달려면 로그인하십시오.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by