Vector Defined by Two Points

조회 수: 22 (최근 30일)
Devinya Herath
Devinya Herath 2011년 6월 1일
I have two points P1(x1, y1) and P2(x2, y2). These are cartesian coordinates. How to calculate the vector P1P2 in matlab?

답변 (2개)

Matt Fig
Matt Fig 2011년 6월 1일
[(x1-x2) (y1-y2)]
  댓글 수: 1
Jan
Jan 2011년 6월 1일
+1. I'd suggest to insert a comma to separate the elements. A beginner might be surprised by the different results for [1-2], [1 -2], [1 - 2]. And to be exact, I don't know what happens, if a line continuator is inserted: [1 -...<NewLine>2],
[1 -<space>...<NewLine>2], [1 -...<NewLine><space>2] ?!
Therefore I always use a comma as separator such that inserted or deleted spaces do cause ambiguities: [1,-2].
Nitpicking, I know.

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


Hamid Reza
Hamid Reza 2013년 6월 8일
%% clear all clc p1=[1,2]; p2=[3,4]; p=distance(p1,p2) line([1 2],[3 4])

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by