How to create an indexing program that removes numbers between values
Mostrar comentarios más antiguos
I have a large data set of numbers that I would like to import so I need help writing a program that can do the following.
1. Find the first negative number within the set. 2. Once first negative number is found, note the positive number that came right before the first negative number found, and remove all data entries until that positive number is found again.
Some examples are...
test1 = [9,-7,7,1,10,-9,9] would print newtest1 = [9 9]
or test2 = [1, 2, 4, -2, 7, 8, 4] would print newtest2 = [1, 2, 4, 4]
Respuesta aceptada
Más respuestas (1)
Andrei Bobrov
el 26 de Jul. de 2017
Editada: Andrei Bobrov
el 28 de Jul. de 2017
ii = find(test2 < 0,1 , 'first')-1;
out = [test2(1:ii-1),test2(test2 == test2(ii))];
after last Andrew's comment
t = cumsum(testOriginal(2,:) < 0) == 0;
out = testOriginal(:,testOriginal(2,:) == testOriginal(2,find(t,1,'last')) | t);
Categorías
Más información sobre Logical 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!