How to split 4D matrix in equal parts?
5 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Ameer Hamza
on 17 Oct 2020
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 Comments
Walter Roberson
on 17 Oct 2020
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.
See Also
Categories
Find more on Image Processing and Computer Vision in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!