How to split 4D matrix in equal parts?

5 次查看(过去 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

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by