Matching coordinates in Matlab
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Jan
am 22 Jan. 2019
Bearbeitet: Jan
am 22 Jan. 2019
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?
Antworten (0)
Siehe auch
Kategorien
Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!