how to know the node number if i know the coordinates values

2 views (last 30 days)
i have 100 nodes and plot on the graph randomly.each node are identify uniquely by node number.
I know the coordinate value of each node but i don't know the node number.
How to get the node number at particular X and Y coordinates
suppose i have value of X and Y is
X=42.3109 Y=21.2031
  2 Comments
Guillaume
Guillaume on 13 Apr 2015
How are the nodes stored? Is it an N x 3 matrix where the columns are node number, x and y? Or something else?
Are the coordinates also stored rounded to 4 decimals or are they infinite precision? That will influence the way the coordinate search is performed.
singh
singh on 13 Apr 2015
yes it coordinate store upto 4 decimals not a infinite precision

Sign in to comment.

Answers (1)

Guillaume
Guillaume on 13 Apr 2015
It's not very clear what you are asking. Assuming you have an N x 3 matrix of nodes, x and y coordinates as such:
nodes = [1 15.2345 23.7891
2 23.1496 47.2365
3 42.3109 21.2031
4 16.7845 21.2031
5 42.3109 47.2145]; %column 1 = node number, 2 = x, 3 = y. rows are nodes
To find the node number for a given coordinate:
x = 72.3109;
y = 21.2031;
nodenumber = nodes(nodes(:, 2) == x & nodes(:, 3) == y, 1)
Note that this assumes that all numbers have been rounded to four decimals. Otherwise the comparison might fail if you obtained what is mathemically the same number through two different operations. Be aware that with floating point numbers (0.1 + 0.1 + 0.1) == 0.3 is false.

Community Treasure Hunt

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

Start Hunting!