How to split 4D matrix in equal parts?

조회 수: 13 (최근 30일)
Iugo
Iugo 2020년 10월 16일
댓글: Iugo 2020년 10월 18일
Hi everyone!
I have here a doubt that consists in how can I split a 4D matrix (112x112x25x100) in equal parts and put it in 2D? This problem appeared because I will use the corrcoef function and it onluy accepts 2D input, so I need to transform this 4D matrix into 2D. And I want to split to avoid problems with the memory because this matrix is kinda big,
Hope you can help me!!
Thanks in advance,
Hugo

답변 (1개)

Ameer Hamza
Ameer Hamza 2020년 10월 17일
You can access a 2D component of a 4D matrix by indexing like this
x = rand(112, 112, 25, 100);
y = x(:,:,1,1); % 3rd dimension can vary to 25 and fourth to 100
Alternatively you can create a 25x100 cell array
x = rand(112, 112, 25, 100);
y = mat2cell(x, size(x,1), size(x,2), ones(size(x,3),1), ones(size(x,4),1));
y = squeeze(y);
  댓글 수: 9
Walter Roberson
Walter Roberson 2020년 10월 17일
For correlating the time series use
M = reshape(permute(x, [4 1 2 3], size(x,4), []);
Now each row is one observation (time) and each column is a variable (pixel location).
The result would, in theory, be a square matrix in which each pixel is correlated against each other pixel.
However... you have 313600 pixels and the correlation matrix would require about 3/4 of a petabyte.
You could break the matrix up into smaller pieces, but even if you manage to assemble it in pieces, you still have the problem that as long as correlation of every pixel to every other pixel is your goal, then your final matrix is going to have to be that size. Your only chance for success is if that is not really your final goal and your actual goal does not need as much information to represent.
Iugo
Iugo 2020년 10월 18일
Thank you so much Walter! I really appreciate your help!
Cheers,
Hugo

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

카테고리

Help CenterFile Exchange에서 Image Processing and Computer Vision에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by