How to remove identical matrix
조회 수: 11 (최근 30일)
이전 댓글 표시
I have about 2000 matrices. They have the same number of columns but different number of rows. Some of these matrices are duplicates with identical number of rows, columns and identical values for all elements.
Here is my question. How do I go through these 2000 matrices and delete all duplicates. Is there a similar function like "unique" for matrices?
Many thanks!
댓글 수: 1
Walter Roberson
2017년 9월 29일
No there is not. How are they stored currently? Are they within a single cell array?
When you say identical values, are you okay if values that differ in a single least significant bit are not considered the same value? Like 1.0 compared to 1.0+eps ? Will the values be created exactly the same way, or is there a need for some tolerance in the comparison due to the fact that two different floating point calculations of the same algebraic value can come out different ?
채택된 답변
OCDER
2017년 9월 29일
%Create a cell array of matrices with same cols but diff rows and values
for k = 1:5
M{k} = 100*rand(k, 6);
end
M{6} = M{1}; %Duplicate of 1
M{7} = M{3}; %Duplicate of 3
M{8} = M{3}; %Duplicate of 3
Ndig = 10; %Number of digits of precision
Mstr = cellfun(@(x) mat2str(x, Ndig), M, 'uniformoutput', false); %Convert to str representation
[~, Midx] = unique(Mstr, 'stable'); %Find unique string
Munq = M(Midx); %Get only the unique matrix
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!