필터 지우기
필터 지우기

How to find unique matrix from given array and corresponding indexes?

조회 수: 3 (최근 30일)
Triveni
Triveni 2021년 8월 28일
댓글: Triveni 2021년 9월 1일
I have
A
A(:,:,1) =
Columns 1 through 2
20 20.05
20.05 20
19.95 20
Column 3
19.95
19.95
20.05
A(:,:,2) =
Columns 1 through 2
20 20.05
20.05 20
19.95 20
Column 3
19.95
19.95
20.05
A(:,:,3) =
Columns 1 through 2
20.05 20
20.05 20
19.95 20
Column 3
19.95
19.95
20.05
>> unique(A)
ans =
19.95
20
20.05
But i need to find out unique matrices and corresponding indexes
B
B(:,:,1) =
Columns 1 through 2
20 20.05
20.05 20
19.95 20
Column 3
19.95
19.95
20.05
B(:,:,2) =
Columns 1 through 2
20.05 20
20.05 20
19.95 20
Column 3
19.95
19.95
20.05
>> index = [1,3]
index =
1 3
In this format B and index.

채택된 답변

Chunru
Chunru 2021년 8월 28일
A(:,:,1) = [ 20 20.05 19.95
20.05 20 19.95
19.95 20 20.05];
A(:,:,2) = [ 20 20.05 19.95
20.05 20 19.95
19.95 20 20.05];
A(:,:,3) = [ 20.05 20 19.95
20.05 20 19.95
19.95 20 20.05];
% Reshape the matrix and find unique along each row
[uA, iA] = unique(reshape(A, [], size(A,3))', 'rows');
B = reshape(uA', size(A,1), size(A,2), [])
B =
B(:,:,1) = 20.0000 20.0500 19.9500 20.0500 20.0000 19.9500 19.9500 20.0000 20.0500 B(:,:,2) = 20.0500 20.0000 19.9500 20.0500 20.0000 19.9500 19.9500 20.0000 20.0500
iA'
ans = 1×2
1 3
  댓글 수: 1
Triveni
Triveni 2021년 9월 1일
Thanks for your answer. It is also working for m*n*i size means A(m,n,1:i)) array.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by