Applying similar functions to many small chunks of large matrices
Show older comments
I have a large matrix and want to apply similar functions across many smaller portions of the matrix. The matrix I am working with has billions of datapoints, so I am building a smaller replica to practice with.
An example of the practice matrix would be...
T = 5;
W = zeros(10,5);
for trial = 1:T
mtest = randi([1,5],10,3);
W(:,trial) = var(mtest,0,2);
end
M = W(:)
lindex = 0:0.2:1.8;
linc = zeros(50,10);
for i = 1:length(lindex)
linc(:,i) = M >= lindex(i);
end
So, you can see this is a 50X10 matrix of 0's and 1's. Each subset that I want to analyze is a 2X1 chunk of the 50X10 matrix (e.g., linc(1:2,1), linc(1:2,2), linc(1:2,3)...all the way to linc(49:50,10)). If I want to do something simple like calculate the percentage of 1's in each subset, that would require 250 calculations. Is there a function I can write to perform such a calculation in one or a few steps?
I have considered for loops, while loops, and splitapply, but none of them seem appropriate here, though I may be wrong.
Any suggestions?
Thank you in advance!
Accepted Answer
More Answers (0)
Categories
Find more on Neighborhood and Block Processing 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!