How to find unique pages in a 3d matrix?
10 次查看(过去 30 天)
显示 更早的评论
If I have 3d matrix like
A = cat(3, [1 2; 3 4], [5 6; 3 4], [5 6; 1 2],[1 2; 3 4])
I want to find unique pages in this matrix so the result should be
result = cat(3, [1 2; 3 4], [5 6; 3 4], [5 6; 1 2])
0 个评论
采纳的回答
Azzi Abdelmalek
2013-2-12
编辑:Azzi Abdelmalek
2013-2-12
A = cat(3, [1 2; 3 4;0 0], [5 6; 3 4; 0 0], [5 6; 1 2;0 0],[1 2; 3 4;0 0])
[n,m,p]=size(A)
a=reshape(A,n,[],1)
b=reshape(a(:),n*m,[])'
c=unique(b,'rows','stable')'
reshape(c,n,m,[])
0 个评论
更多回答(1 个)
Honglei Chen
2013-2-12
You can try to reshape it to 2D first, then remove duplicates. For example
A = cat(3, [1 2; 3 4], [5 6; 3 4], [5 6; 1 2],[1 2; 3 4])
Ar = reshape(A,[4 4])
Ar = unique(Ar.','rows','stable').'
reshape(Ar,2,2,[])
I don't quite understand your second question. I think MATLAB automatically removes empty pages. What do you mean by "empty pages"?
3 个评论
Honglei Chen
2013-2-12
Your version does not support 'stable' option, try the following
A = cat(3, [1 2; 3 4], [5 6; 3 4], [5 6; 1 2],[1 2; 3 4])
Ar = reshape(A,[4 4])
[dummy,idx] = unique(Ar.','rows')
reshape(Ar(:,sort(idx)),2,2,[])
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!