필터 지우기
필터 지우기

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

조회 수: 10 (최근 30일)
LISSA DUVVU
LISSA DUVVU 2022년 2월 16일
편집: Stephen23 2022년 2월 16일
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