How to get Unique values from two columns at a time?

10 次查看(过去 30 天)
Hello,
I have a matrix
0.075278 0.213 18 127
0.075278 0.220 16 127
0.075278 0.248 31 129
0.075278 0.307 22 129
0.075278 0.323 14 129
0.241944 0.217 26 129
0.241944 0.223 14 129
0.241944 0.487 22 129
0.241944 0.677 16 129
12.82861 0.247 12 135
If column 1 and 4 have unique values i need to keep only one and have to remove remaining
I want my answer as
0.075278 0.220 16 127
0.075278 0.323 14 129
0.241944 0.677 16 129
12.82861 0.247 12 135

采纳的回答

Stephen23
Stephen23 2022-2-16
编辑:Stephen23 2022-2-16
You could use UNIQUETOL, for example:
M = [0.075278,0.213,18,127;0.075278,0.220,16,127;0.075278,0.248,31,129;0.075278,0.307,22,129;0.075278,0.323,14,129;0.241944,0.217,26,129;0.241944,0.223,14,129;0.241944,0.487,22,129;0.241944,0.677,16,129;12.82861,0.247,12,135]
M = 10×4
0.0753 0.2130 18.0000 127.0000 0.0753 0.2200 16.0000 127.0000 0.0753 0.2480 31.0000 129.0000 0.0753 0.3070 22.0000 129.0000 0.0753 0.3230 14.0000 129.0000 0.2419 0.2170 26.0000 129.0000 0.2419 0.2230 14.0000 129.0000 0.2419 0.4870 22.0000 129.0000 0.2419 0.6770 16.0000 129.0000 12.8286 0.2470 12.0000 135.0000
[~,X] = uniquetol(M(:,[1,4]),'highest','ByRows',true);
N = M(X,:)
N = 4×4
0.0753 0.2200 16.0000 127.0000 0.0753 0.3230 14.0000 129.0000 0.2419 0.6770 16.0000 129.0000 12.8286 0.2470 12.0000 135.0000
  5 个评论
LISSA DUVVU
LISSA DUVVU 2022-2-16
nope I used UNIQUETOL, but it is not working and here is the error
Error using uniquetol
Tolerance value TOL must be a real, full (non-sparse), positive numeric scalar of type single or double.
Stephen23
Stephen23 2022-2-16
编辑:Stephen23 2022-2-16
@LISSA DUVVU: please show the exact code that you tried.
Please check the help for your installed MATLAB version. Check the syntaxes that it supports. It may be that you need to also supply the tol argument, or something similar.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Optimization Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by