필터 지우기
필터 지우기

Matching coordinates in Matlab

조회 수: 2 (최근 30일)
SAMUEL AYINDE
SAMUEL AYINDE 2019년 1월 22일
편집: 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에서 Logical에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by