Split 7000x4000 matrix in 10x10 matrices?

1 view (last 30 days)
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

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 7 Aug 2016
Edited: Azzi Abdelmalek on 7 Aug 2016
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 Comments
gooniyath
gooniyath on 10 Aug 2016
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 on 10 Aug 2016
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.

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 7 Aug 2016
Edited: Image Analyst on 7 Aug 2016
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 Comment
Image Analyst
Image Analyst on 10 Aug 2016
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);

Sign in to comment.

Categories

Find more on Creating and Concatenating Matrices 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!