Split 7000x4000 matrix in 10x10 matrices?
Show older comments
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
More Answers (1)
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
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);
Categories
Find more on Logical 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!