Filter löschen
Filter löschen

dividing a matrix into 5 different matrices

1 Ansicht (letzte 30 Tage)
cormac spillane
cormac spillane am 25 Apr. 2015
Bearbeitet: Stephen23 am 25 Apr. 2015
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

Antworten (1)

Stephen23
Stephen23 am 25 Apr. 2015
Bearbeitet: Stephen23 am 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!

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by