Split 4000x10 Matrix into 400 10x10 Matrices and calculate stats for each matrix?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Hi
Im trying to split a 4000x10 Matrix into 400 10x10 Matrices? Once the matrix is split up I need to calcualte the mean, median and standard deviation for each of these matrices.
Regards Akshay
1 Commento
Risposte (2)
Geoff Hayes
il 1 Ago 2016
A = randi(255,4000,10);
B = reshape(A,10,10,[]);
Then you can iterate over each of the 400 matrices to calculate your statistics
for k=1:size(B,3)
mtx = B(:,:,k); % the kth 10x10 matrix
% calculate the mean and standard deviation
end
2 Commenti
Stephen23
il 2 Ago 2016
@Akshay J: use permute beforehand to swap the columns and rows:
B = permute(A,[2,1,3]);
B = reshape(B,...)
you might want to use permute again after that too.
Image Analyst
il 2 Ago 2016
Akshay, you can use blockproc to process a block of your array (or image) by moving the block, which can be of any size, in "jumps" that you specify. So you have a 4000 row by 10 column matrix. You can move in jumps of 10 rows and then compute the functions you want. Here is the code (requires the Image Processing Toolbox for the blockproc() function):
% Create sample data.
yourMatrix = randi(9, 4000, 10);
% Define how we will move in jumps over the array.
blockSize = [10, 1];
% Define the function that we will apply to each block.
% First in this demo we will take the median value in the block
% and create an equal size block where all elements have the median value.
medianFilterFunction = @(theBlockStructure) median(theBlockStructure.data(:));
% Block process the array to replace every pixel in the
% 10 pixel by 10 pixel block by the median of the pixels in the block.
blockyImageMedian = blockproc(single(yourMatrix), blockSize, medianFilterFunction); % Works.
[rows, columns] = size(blockyImageMedian)
% Block process the image to replace every pixel in the
% 10 pixel by 10 pixel block by the mean of the pixels in the block.
% The matrix is 4000 rows by 10 pixels across which will give 4000/10 = 400 blocks.
meanFilterFunction = @(theBlockStructure) mean2(theBlockStructure.data(:));
blockyImageMean = blockproc(yourMatrix, blockSize, meanFilterFunction);
[rows, columns] = size(blockyImageMean)
% Block process the image to replace every pixel in the
% 10 pixel by 10 pixel block by the standard deviation of the pixels in the block.
StDevFilterFunction = @(theBlockStructure) std(double(theBlockStructure.data(:)));
blockyImageSD = blockproc(yourMatrix, blockSize, StDevFilterFunction);
[rows, columns] = size(blockyImageSD)
0 Commenti
Vedere anche
Categorie
Scopri di più su Computer Vision with Simulink in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!