Filter löschen
Filter löschen

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

10 Ansichten (letzte 30 Tage)
LISSA DUVVU
LISSA DUVVU am 16 Feb. 2022
Bearbeitet: Stephen23 am 16 Feb. 2022
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

Akzeptierte Antwort

Stephen23
Stephen23 am 16 Feb. 2022
Bearbeitet: Stephen23 am 16 Feb. 2022
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 Kommentare
LISSA DUVVU
LISSA DUVVU am 16 Feb. 2022
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 am 16 Feb. 2022
Bearbeitet: Stephen23 am 16 Feb. 2022
@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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Optimization Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by