How calculate distance between points in matrices?

6 ビュー (過去 30 日間)
Sebastian
Sebastian 2018 年 8 月 3 日
コメント済み: Bob Thompson 2018 年 8 月 3 日
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

回答 (1 件)

Bob Thompson
Bob Thompson 2018 年 8 月 3 日
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 件のコメント
Matt J
Matt J 2018 年 8 月 3 日
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.
Bob Thompson
Bob Thompson 2018 年 8 月 3 日
That sounds like something worth trying.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by