Matching coordinates in Matlab
조회 수: 2 (최근 30일)
이전 댓글 표시
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
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?
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!