Matching coordinates in Matlab

1 次查看(过去 30 天)
SAMUEL AYINDE
SAMUEL AYINDE 2019-1-22
Please find the attached matlab files: bigUphi.mat and wangphi.mat.
x_bigUphi = bigUphi(:,1);
y_bigUphi = bigUphi(:,2);
z_bigUphi = bigUphi(:,3);
phi_bigUphi = bigUphi(:,4);
x_wangphi = wangphi(:,1);
y_wangphi = wangphi(:,2);
z_wangphi = wangphi(:,3);
phi_wangphi = wangphi(:,4);
All the positions (x,y,z) in bigUphi are also in wangphi. But they do not follow the same order.
I want to create another column vector, phiuse. To do this, for each position (x_bigUphi, y_bigUphi, z_bigUphi) in bigUphi, I want to search for the same position (x_wangphi, y_wangphi, z_wangphi) in wangphi. Then I want to replace the phi_bigUphi of that position with phi_wangphi of that position.
I have tried the code below. It worked for 2D case (x,y), but it is not working for the 3D case (x,y,z). Please, help me.
phiuse = zeros(2583,1);
for i = 1:2583
phiuse(i,1) = phi_wangphi(and((and(abs(wangphi(:,1)-bigUphi(i,1))<1e-10,abs(wangphi(:,2)-bigUphi(i,2))<1e-10)),abs(wangphi(:,3)-bigUphi(i,3))<1e-10));
end
  2 个评论
Jan
Jan 2019-1-22
编辑:Jan 2019-1-22
A simplification of the code:
phiuse = zeros(2583,1);
for i = 1:2583
dist = abs(wangphi - bigUphi(i, :)); % Auto-expand: >=R2016b
match = all(dist < 1e-10, 2);
phiuse(i) = phi_wangphi(match);
end
Is this wanted? Is it guaranteed, that there is one matching point in every case?
You state, that "it is not working". Please explain, what this means. It is easier to fix an error than to guess, what the error is.
Maybe 1e-10 is not sufficient?
Did you try ismembertol already?
SAMUEL AYINDE
SAMUEL AYINDE 2019-1-22
编辑:SAMUEL AYINDE 2019-1-22
Hi Jan,
Thank you so much for your reply.
I checked it properly. The discretization is different in each case. I guess that is the reason it did not work.
Thank you so much.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by