How to create an indexing program that removes numbers between values
Show older comments
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]
Accepted Answer
More Answers (1)
Andrei Bobrov
on 26 Jul 2017
Edited: Andrei Bobrov
on 28 Jul 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);
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!