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 次查看(过去 30 天)
显示 更早的评论
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]
采纳的回答
JESUS DAVID ARIZA ROYETH
2019-12-4
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 NaNs 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!