필터 지우기
필터 지우기

Converting a 3D Matrix to multiple 2D matrices

조회 수: 1 (최근 30일)
Aldo Hernandez
Aldo Hernandez 2021년 1월 17일
편집: Bruno Luong 2021년 1월 17일
I have a 3D matrix, 1000 x 1000 x 40
I want to convert this matrix to 40 different matrices, 1000 x 1000 each. I suppose I am asking for the inverse of repmat, however searches into that have not led to progress.
Any help is appreciated.
  댓글 수: 2
Athrey Ranjith Krishnanunni
Athrey Ranjith Krishnanunni 2021년 1월 17일
편집: Athrey Ranjith Krishnanunni 2021년 1월 17일
Something like this?
largeMatrix = randn(1000,1000,40);
smallMatrixArray = cell(40,1);
for iOuterDim = 1:40
smallMatrixArray{iOuterDim} = largeMatrix(:,:,iOuterDim);
end
Steven Lord
Steven Lord 2021년 1월 17일
I want to convert this matrix to 40 different matrices
Why? What benefit do you hope to gain by doing that instead of indexing into the array to retrieve the appropriate slice when needed?
A = reshape(1:(3*4*5), [3 4 5]);
A4 = A(:, :, 4)
A4 = 3×4
37 40 43 46 38 41 44 47 39 42 45 48
What happens when or if you expand your problem sizes to an array of size 10000 in the third dimension? Your workspace would become awfully cluttered with ten thousand and one arrays in it.

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

채택된 답변

Bruno Luong
Bruno Luong 2021년 1월 17일
편집: Bruno Luong 2021년 1월 17일
Assuming A is array 1000 x 1000 x 40
C = num2cell(A,[1 2]);
  댓글 수: 2
Athrey Ranjith Krishnanunni
Athrey Ranjith Krishnanunni 2021년 1월 17일
You'll have to write
C = shiftdim(num2cell(A,[1 2]));
to get rid of the leading singleton dimensions, though.
Bruno Luong
Bruno Luong 2021년 1월 17일
Well it is nicer but it is not requirement by OP.
C{k} still give the the kth matrix as requested.

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by