Create a matrix [3xm] with the elements of a matrix [3,n] in the order given by vector k[m]

1 回表示 (過去 30 日間)
Hello,
My brain is going to explode. I think the solution is easy, but I seem to not get it. I hope my explaination is good enough. The files are attached and my code is down bellow.
I have 2 STL files, which I convert to points. For each tooth I get a matrix with three rows and different number of rows, m and n. I use the function
[k,dist] = dsearchn()
to get the nearest point from tooth 1 to 2.
  • k is a vector with the elements of matrix 1 which contains the nearest point. So if the first element of k is e.g. 5843 that means that the nearest point in Matrix 1 of the first point in Matrix 2 is the point described in the 5843 element of Matrix 1.
  • dist is just the distances between the points.
Now I would like to plot the distance line between said points and here my brain gets knotted. MATLAB will not plot it because the m and n are different.
My code is this:
Input1 = 'F.O. - 6 left up_centerd_rotated.stl';
Input2 = 'L.O. - 6 left up_centerd_rotated.stl';
FV1 = stlread(Input1); % Get the Values of F, V and N
FV2 = stlread(Input2); % Get the Values of F, V and N
FV1Unique = unique(FV1.vertices,'rows');
FV2Unique = unique(FV2.vertices,'rows');
[k,dist] = dsearchn(FV1Unique,FV2Unique);
subplot(1,2,1)
plot3(FV1Unique(:,1),FV1Unique(:,2), FV1Unique(:,3),'ko')
hold on
plot3(FV2Unique(:,1),FV2Unique(:,2),FV2Unique(:,3),'*g')
hold on
plot3(FV1Unique(k,1),FV1Unique(k,2), FV1Unique(k,3),'*r')
legend('Data Points','Query Points','Nearest Points','Location','sw')
subplot(1,2,2)
plot3([FV2Unique(:,1),FV1Unique(k,1)],[FV2Unique(:,2),FV1Unique(k,2)],[FV2Unique(:,3),FV1Unique(k,3)]); %This is my best try
The last line is my best try. It does work, but the lines drawn are not correct so I must have made a mistake (probably in the last line).
If this doesn't work, I thought of creating a vector of the size m (as k) and taking the values of FV1Unique as given by k and then plotting, but I fail to create the vector.
Thank you for taking the time.

採用された回答

Bruno Luong
Bruno Luong 2020 年 8 月 26 日
編集済み: Bruno Luong 2020 年 8 月 26 日
plot3(...
[FV2Unique(:,1),FV1Unique(k,1)]',...
[FV2Unique(:,2),FV1Unique(k,2)]',...
[FV2Unique(:,3),FV1Unique(k,3)]');
  3 件のコメント
Bruno Luong
Bruno Luong 2020 年 8 月 26 日
編集済み: Bruno Luong 2020 年 8 月 26 日
Separate the lines is just an esthetic change.
The transposition ' is what makes the difference. When you call PLOT, PLOT3 with array input, the lines connect along the first dimension, and there are as many lines as the columns, in your case FV2Unique to the closest FV1Unique.
Diego Hens
Diego Hens 2020 年 8 月 26 日
Ok thanks, understood :)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by