How calculate distance between points in matrices?
18 views (last 30 days)
Show older comments
Hi, I have 2 big matrices (m x 3) about 250000 points (xyz). These are coordinate of points. How find distance between some points as: a) from (0 to 10> mm, b) from (10 to 20> mm, c) from (20 to 30> mm, d) from (30 to 40> mm, e) above 40 mm. Next I want to find these distance and plot in colours: a) blue b) green c) yellow d) orange e) red. I suppose that there should be command find between matrices point to point and write to a matrix A_XYZxyz(n x 6), B, C, D. How to do in in very quick waY. Thnx
0 Comments
Answers (1)
Bob Thompson
on 3 Aug 2018
The distance between two points can be determined using the Pythagorean theorem.
d = sqrt((x2-x1)^2+(y2-y1)^2+(z2-z1)^2);
In order to set colors you can use logic indexing.
color = cell(size(d));
color{d<10} = 'blue';
color{d>=10&d<20} = 'green';
... % Other colors
If you're wanting to actually set the colors in a plot, then just look up the color codes and set them accordingly.
2 Comments
Matt J
on 3 Aug 2018
Sebastian's comment moved here
Bob, I supposed that I need calculate a distance in this way. Maybe solution is analyse 1 matrice from 1st point to the end with another every point matrice. But if I have in 3 dimensional system, when 0 is inside in the block this calculation is useless (if Y=-4 and Y=4 it is the same). Maybe I need cut it in slices Z every 5 mm. Look at picture attached.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!