Working with a set of matrices

조회 수: 2 (최근 30일)
Lorcan O'Connor
Lorcan O'Connor 2021년 4월 3일
댓글: Lorcan O'Connor 2021년 4월 3일
I want to generate a finite matrix group by starting with the S ={identity} and multiplying by some generators until S no longer grows in size.
Is there an efficient way to deal with a "set" like this, without manualling checking for duplicates? For example, it seems awkward if you use cell arrays to store the elements of S.
  댓글 수: 2
Matt J
Matt J 2021년 4월 3일
For example, it seems awkward if you use cell arrays to store the elements of S.
Why?
Lorcan O'Connor
Lorcan O'Connor 2021년 4월 3일
Well say I multiply everything in the cell array by a matrix and only want to take the new elements, how do I efficiently take a “set Union” (or even check if a matrix is in the array), without just looping and checking everything?

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

채택된 답변

Matt J
Matt J 2021년 4월 3일
편집: Matt J 2021년 4월 3일
I'm not sure I will fully understand the task without seeing an example. However, if S is organized as an MxNxP array,
[M,N]=deal(3,3);
S=cat(3,eye(M,N), randi(5,M,N), eye(M,N) )
S =
S(:,:,1) = 1 0 0 0 1 0 0 0 1 S(:,:,2) = 4 5 4 2 1 3 1 5 2 S(:,:,3) = 1 0 0 0 1 0 0 0 1
then you can get rid of duplicate slices with
s=reshape(S,[],size(S,3));
S=reshape( unique(s.','rows').', M,N,[])
S =
S(:,:,1) = 1 0 0 0 1 0 0 0 1 S(:,:,2) = 4 5 4 2 1 3 1 5 2
If S contains non-integer matrices, you will probably need to use uniquetol() instead of unique().
  댓글 수: 1
Lorcan O'Connor
Lorcan O'Connor 2021년 4월 3일
Thanks a lot that's exactly what I needed

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by