Sum the component of a matrix till a certain value
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
luca
el 2 de Sept. de 2019
Comentada: luca
el 2 de Sept. de 2019
Hi,
given the vector matrix M= [2 4 4 5 6 16 8 9 21 3 5 8 12 34 5 6 8;
2 4 2 5 7 8 8 9 1 12 5 8 12 3 8 6 8]
I want to obtain a new matrix S with the same component but cutted at the column X when the sum repeated for each single column exceed a specific value Y.
So if in our case Y=80. the new matrix S would be
S = [2 4 4 5 6 16; 2 4 2 5 7 8 ], in this case the sum of the elements in the column reach 65. (2+2+4+4+4+2+5+5+6+7+16+8)
Adding the 7th column we obtain 81, exceeding our limit. That's why we cut at the column X=6, obtaining S.
Does someone know hot to implement this?
0 comentarios
Respuesta aceptada
madhan ravi
el 2 de Sept. de 2019
Editada: madhan ravi
el 2 de Sept. de 2019
ix = cumsum(M(:))<80;
v = mod(nnz(ix),size(M,1));
[~,c] = ind2sub(size(M),nnz(ix));
Wanted = M(:,1:c-(v~=0))
4 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices 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!