How to iteratively split a matrix into multiple matrices according to a condition?
Mostrar comentarios más antiguos
I have a 2 column matrix with many many rows.
It's been sorted according to the values in the first column.
I now want to split the matrix into ten matrices.
Those values in the first column which are 0-10% of the highest value will go in one matrix, those that are 10-20% of the highest value will go in the next... you get the idea.
How would I go about doing this? I presume a for loop is involved, but am struggling to make it work. Any advice would be very much appreciated - thank you!
Respuesta aceptada
Más respuestas (1)
Jan
el 20 de Feb. de 2018
M = rand(100, 3); % Your data
[~, ~, bin] = histcounts(M(:, 1), 10); % Split first column into 10 groups
C = splitapply(@(x) {x}, M, bin); % 10 cells
Categorías
Más información sobre Matrix Indexing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!