Effacer les filtres
Effacer les filtres

dividing a matrix into 5 different matrices

1 vue (au cours des 30 derniers jours)
cormac spillane
cormac spillane le 25 Avr 2015
Modifié(e) : Stephen23 le 25 Avr 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

Réponses (1)

Stephen23
Stephen23 le 25 Avr 2015
Modifié(e) : Stephen23 le 25 Avr 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!

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by