dividing a matrix into 5 different matrices
1 view (last 30 days)
Show older comments
Hello, I am looking to divide a large matrix Ds into 5 sections (the first 20% being the top 20% and so on), so far i have done this to get s1 the rounded figure for each 20%.
n = size(Ds);
s = n(1,1)/5;
s1 = round(s);
i was just cannot figure out the next step? im sure its very simplistic just cannot seem to get it out? any information regarding this topic would be greatly appreciated.
regards, cormac
0 Comments
Answers (1)
Stephen23
on 25 Apr 2015
Edited: Stephen23
on 25 Apr 2015
There is no general solution to this as it could be defined in different ways depending on the number of rows in the matrix: what is 20% of a one row matrix? 20% of a two row matrix? 20% of a four row matrix?
Obviously if the number of rows of the matrix is a multiple of the blocks that you want, then the solution is easy using mat2cell and some simple division to calculate how many rows per block:
>> A = rand(10,4);
>> N = 5;
>> X = size(A);
>> B = mat2cell(A, X(1)/N * ones(1,N), X(2))
B =
[2x4 double]
[2x4 double]
[2x4 double]
[2x4 double]
[2x4 double]
If you can specify how to work with numbers of rows that are not multiples of the number of blocks, then we can show you how to code this too!
0 Comments
See Also
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!