Find the unique pair of coordinates in matrix and depending on the distance matrix, retain the minimum distance matrix and replace the other coordinate pair by NaN
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Praveen GB
il 4 Dic 2019
Risposto: JESUS DAVID ARIZA ROYETH
il 4 Dic 2019
I have two input matrices ( P and R) and a Distance matrix (distance)
P=[1315.2,832.2
1317.2,808.8
1510.8,514.4
1354.7,743
1519.1,873
1382.7,736.6]
R=[1318,816
1318,816
1515,515
1346,740
1515,867
1346,740]
distance= [16.43
7.24
4.2
9.19
7.2
36]
I want to find out unique values of R and from the distance matrices, which ever distance is lesser, retain the R value as per minimum distance between two pairs of coordinates and remaining replace it with NaN
The output should look like this:
P_new=[1315.2,832.2
1317.2,808.8
1510.8,514.4
1354.7,743
1519.1,873
1382.7,736.6]
R_new = [NaN,NaN
1318,816
1515,515
1346,740
1515,867
NaN,NaN]
distance_new = [NaN
7.24
4.2
9.19
7.2
NaN]
% P, R and distance are input matrices
P=[1315.2,832.2;1317.2,808.8;1510.8,514.4;1354.7,743;1519.1,873;1382.7,736.6]
R=[1318,816;1318,816;1515,515;1346,740;1515,867;1346,740]
distance= [16.43;7.24;4.2;9.19;7.2;36]
% P_new, R_new and distance_new are the required output matrices
P_new=[1315.2,832.2;1317.2,808.8;1510.8,514.4;1354.7,743;1519.1,873;1382.7,736.6]
R_new = [NaN,NaN;1318,816;1515,515;1346,740;1515,867;NaN,NaN]
distance_new = [NaN;7.24;4.2;9.19;7.2;NaN]
4 Commenti
Risposta accettata
JESUS DAVID ARIZA ROYETH
il 4 Dic 2019
a solution:
[uv,~,idx] = unique(R,'rows');
v = accumarray(idx,distance,[],@min);
eliminate=~ismember([R distance],[uv v],'rows');
P_new=P
R_new=R;
R_new(eliminate,:)=nan
distance_new=distance;
distance_new(eliminate)=nan
Più risposte (0)
Vedere anche
Categorie
Scopri di più su NaNs in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!