selecting certain values from a list
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have this list below (call it A), and i wish to find the last value of a group of numbers. if you look at the numbers, they are bunched together in groups (not always consecutively), and i only want the last number in each group.
A =
8
9
106
107
109
110
244
245
325
326
329
334
335
483
484
485
486
527
528
690
691
So the new list (call it B), should look like this..
B =
9
110
245
335
486
528
691
I was thinking of making a for loop (i=1:length(A)) and doing a 'find' to see if a number exists in between that number and +20 after it (each new group of numbers never exceeds beyond 20).
is this possible? thank you in advance
0 comentarios
Respuesta aceptada
Paulo Silva
el 28 de Jun. de 2011
M=[ 8 9 106 107 109 110 244 245 325 326 329 334 335 483 484 485 486 527 528 690 691]
d=diff(M); %find the diference between consecutive values
[M(d>1);M(end)] %get the values with diference bigger than 1
append M(end) because the last one is always the last from a group and the diference function doesn't catch it
6 comentarios
Sean de Wolski
el 28 de Jun. de 2011
OP: "I was thinking of making a for loop (i=1:length(A)) and doing a 'find' to see if a number exists in between that number and +20 after it (each new group of numbers never exceeds beyond 20)."
so basically anywhere there's a gap of more than 20 it fails.
Más respuestas (1)
Ver también
Categorías
Más información sobre Matrix Indexing 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!