필터 지우기
필터 지우기

Creating a vector from a set of coordinates

조회 수: 19 (최근 30일)
Joe Cousins
Joe Cousins 2021년 8월 20일
댓글: Fangjun Jiang 2022년 3월 28일
If I have a set of coordinates of:
x = [10.1, 5.4, 7.3, ...];
y = [2.3, 7.4, 8.8, ...];
How can I create a single vector that assigns each point to an integer such that index = [1 2 3 ...]. E.g. the point with index 1 has the coordinates of x(1), y(1)
Appreciate any help.

채택된 답변

Bjorn Gustavsson
Bjorn Gustavsson 2021년 8월 20일
If you do:
r = [x(:),y(:)]; % (:) forms column-vectors of any-dimensional array.
Then you will find:
p1 = r(1,:)
HTH
  댓글 수: 2
Sean Ivan Roxas
Sean Ivan Roxas 2022년 3월 28일
If I have N number of x and y coordinates, how do I index each pair of coorditnates from 1 to N and store these indices in a vector?
Fangjun Jiang
Fangjun Jiang 2022년 3월 28일
There is no need to "store the indices". length(x), numel(x) or size(x) could return the size information if that is what you want.

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

추가 답변 (1개)

Fangjun Jiang
Fangjun Jiang 2021년 8월 20일
You mean like this? There is really no need to do this. Please explain the need.
x = [10.1, 5.4, 7.3];
y = [2.3, 7.4, 8.8];
index=[x;y]';
index(1,:)
ans =
10.1000 2.3000

카테고리

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

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by