Split 7000x4000 matrix in 10x10 matrices?
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi,
I have a 7000x4000 Matrix of topographic data that I need to split into 10x10 matrices (Split by going every 10 rows and 10 columns). Any recommendations on how to go about it? Also once the matrix is split into the 10x10 matrices, I need it to randomly select 1 number out of the 100 in each matrices?
Regards, Akshay
댓글 수: 0
채택된 답변
Azzi Abdelmalek
2016년 8월 7일
편집: Azzi Abdelmalek
2016년 8월 7일
A=randi(100,7000,4000) % Example
B=mat2cell(A,10*ones(700,1),10*ones(400,1))
C=cellfun(@(x) x(randi(100)),B)
If you have Image Processing toolbox you can use blockproc function
C1=blockproc(A,[10 10],@(x) x.data(randi(100)))
댓글 수: 2
Image Analyst
2016년 8월 10일
You can randomly pick with randn. In fact I did that in my comment to my answer above - I just slightly modified my original answer that used a uniform distribution. It will randomly pick a single point from each of the 10 units-by-10 units tile. The points are centered at the middle of the 10x10 tile and have a radial standard deviation that you specify. It also clips in case the Normal random number is outside the tile. Take a look at my answer.
추가 답변 (1개)
Image Analyst
2016년 8월 7일
편집: Image Analyst
2016년 8월 7일
One way:
rows = 7000;
columns = 4000;
% Get starting points in upper left.
[R, C] = meshgrid(1:10:rows, 1:10:columns);
% Get coordinates of random point in each 10x10 tile
R = round(R + 10 * rand(size(R)));
C = round(C + 10 * rand(size(C)));
Now R and C have all of your coordinates - one from each 10 by 10 tile over the whole image. You can get a value from, say, the tile in the second row and the 5th column of tiles like this
value = yourMatrix(R(2), C(5));
Where yourMatrix is your full sized 7000x4000 matrix.
댓글 수: 1
Image Analyst
2016년 8월 10일
Solution to your request for points to be normally distributed from the center of each 10-by-10 tile.
rows = 7000;
columns = 4000;
% Get starting points in upper left.
[R, C] = meshgrid(1:10:rows, 1:10:columns);
% Get coordinates of random point in each 10x10 tile
mu = 5;
sigma = 2.5;
rRand = mu + sigma * randn(size(R));
cRand = mu + sigma * randn(size(C));
% Don't let go less than 0
rRand(rRand<0) = 0;
cRand(cRand<0) = 0;
% Don't let go more than 10
rRand(rRand>10) = 10;
cRand(cRand>10) = 10;
% Get the random coordinates - one from each 10-by-10 tile.
randomRows = round(R + rRand);
randomCols = round(C + cRand);
scatter(randomRows(:), randomCols(:), 1);
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!