How to remove duplicate rows from .mat file or text file with out sorting?

조회 수: 5 (최근 30일)
Ram
Ram 2018년 7월 1일
편집: jonas 2018년 7월 1일
Hello all, I have 64954930*3 matrix. There are duplicate rows are exist. How can i delete with out sorting of original matrix.
This is my code
load('myfile.mat');
%A = unique(myfile(:,:),'rows');
A = myfile(:,:);
% B = unique(A,'stable');
% save('B.mat','B');
%C = setxor(A,'rows','stable');
should i write forloop? i used different formats. but getting various errors. such as sort input arguments of struct; Undefined myfile. Kindly help me. Thanks in advance.
  댓글 수: 7
Ram
Ram 2018년 7월 1일
i tried it too. may be can you suggest with for loop with small example. cause it doesn't works to me. thanks in advance!
jonas
jonas 2018년 7월 1일
Nothing is going to work for you if you get the message:
Undefined function or variable 'A'.
becuause it means there is no variable called A...

댓글을 달려면 로그인하십시오.

채택된 답변

jonas
jonas 2018년 7월 1일
Seems you are really close to finding the solution.
out=unique(A,'rows','stable')
should give you the unsorted unique rows :)
  댓글 수: 14
Ram
Ram 2018년 7월 1일
@jonas, when i use above code for 54954930*3 matrix. output is 9800*3 But when i use below code
A = load('myfile1.mat'); %myfile consists a large data
A = A.myfile;
out=unique(A,'rows','stable');
out is 166603041*3--- which data is correct??
i want to remove only identical rows in 3 columns
let say, A = 1 1 1;1 1 1; 1 2 1; 1 2 3;
out = 1 1 1; 1 2 1; 1 2 3.
i hope, i am not confusing.
jonas
jonas 2018년 7월 1일
편집: jonas 2018년 7월 1일
As Paolo previously said, you are working with floating point numbers. That is why you need to use uniquetol and not unique. You need to define what a duplicate is (by setting a tolerance). If you set the tolerance to zero, then you will probably end up with the same result using both functions. However, are 1.0000000 and 1.00000001 duplicates? That's what you define with tolerance, i.e. the max difference between two numbers for them to be defined as same number.
Or simply put. Do you still have duplicates after you use unique? Then you need to use uniquetol to remove rows that are almost identical to other rows.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Workspace Variables and MAT-Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by