Split 4000x10 Matrix into 400 10x10 Matrices and calculate stats for each matrix?
조회 수: 1 (최근 30일)
이전 댓글 표시
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
답변 (2개)
Geoff Hayes
2016년 8월 1일
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
Stephen23
2016년 8월 2일
@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
2016년 8월 2일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Computer Vision with Simulink에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!