dividing a matrix into 5 different matrices

1 次查看(过去 30 天)
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

回答(1 个)

Stephen23
Stephen23 2015-4-25
编辑:Stephen23 2015-4-25
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!

类别

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