MATLAB Answers

Creating a vector from a set of coordinates

8 views (last 30 days)
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.

Accepted Answer

Bjorn Gustavsson
Bjorn Gustavsson on 20 Aug 2021
If you do:
r = [x(:),y(:)]; % (:) forms column-vectors of any-dimensional array.
Then you will find:
p1 = r(1,:)
HTH

More Answers (1)

Fangjun Jiang
Fangjun Jiang on 20 Aug 2021
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

Tags

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!