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

采纳的回答

Azzi Abdelmalek
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 个评论
gooniyath
gooniyath 2016-8-10
Thanks for the answer Azzi. Is it possible to randomize with normal distribution? I have the calculated standard deviation and mean.
Image Analyst
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
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
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 CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by