Borrar filtros
Borrar filtros

Split 837 x 2 matrix into smaller n x 2 matrices

2 visualizaciones (últimos 30 días)
Royvg94
Royvg94 el 17 de Sept. de 2015
Comentada: Royvg94 el 17 de Sept. de 2015
I have an 837 x 2 matrix with in the first column time, and in the second column some other values. I would like to split the matrix based on the difference between the time values in the first column.
For example: If you have this matrix:
A = [3 78; 6 52; 9 63; 300 123; 303 143; 306 107; 600 503]
I would like to split it between 9 and 300 and 306 and 600. So lets say if the difference in the first column is bigger than 50. So that i get those matrices out of it:
B = [3 78; 6 52; 9 63] C = [300 123; 303 143; 306 107] D = [600 503]
I already know how to calculate differences between them, now i only need to know how to split the matrices this way.
Thanks for the help!

Respuesta aceptada

Matt J
Matt J el 17 de Sept. de 2015
Editada: Matt J el 17 de Sept. de 2015
A = [3 78; 6 52; 9 63; 300 123; 303 143; 306 107; 600 503]
[m,n]=size(A);
z=diff([0,find(diff(A(:,1))>50).',m]);
Acell=mat2cell(A,z,n);
>> [B,C,D]=deal(Acell{:})
B =
3 78
6 52
9 63
C =
300 123
303 143
306 107
D =
600 503

Más respuestas (0)

Categorías

Más información sobre Multidimensional Arrays en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by