I would like to partition a matrix by an approximate even amount of rows. For example, if I have a matrix by these dimensions 155 x 1000, how can I partition it by 10 where each new matrix has the approximate dimensions 15 X 1000?
Matlab matrix partitioning
3.9k Views Asked by lurodrig At
2
There are 2 best solutions below
0

Is this what you want?
%Setup
x = rand(155,4); %4 columns prints on my screen, the second dimension can be any size
n = size(x,1);
step = round(n/15);
%Now loop through the array, creating partitions
% This loop just displays the partition plus a divider
for ixStart = 1:step:n
part = x( ixStart:(min(ixStart+step,end)) , : );
disp(part);
disp('---------')
end
The only trick here is the use of the end
keyword within a function evaluation in the subscripting. Without using the keyword you could use size(x,1)
, but that is a bit harder to read.
How about this: