How to create an indexing program that removes numbers between values
Afficher commentaires plus anciens
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]
Réponse acceptée
Plus de réponses (1)
Andrei Bobrov
le 26 Juil 2017
Modifié(e) : Andrei Bobrov
le 28 Juil 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);
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!