To find the number of sections with negative values
2 visualizzazioni (ultimi 30 giorni)
I have data in the form of a matrix with 3 columns. On the third column it is the velocities. A sample look like this:
1 3 5
2 5 8
3 7 6
4 8 -1
5 9 -3
6 8 -1
7 9 1
8 5 2
It is a data file (.dat). How can I program in Matlab so that the code look for negative values from the beginning of the 3rd column (velocity). When it see first negative value on the 3rd column, check if it is negative for at least next consecutive 5 rows. If at least 5 consecutive rows are (only third column) are negative, take the whole consecutive rows with negative values as 'section1'. Then again look where the next negative value starts, if it find next negative value, again check if atleast next 5 consecutive rows have negative values, if yes, take the whole consecutive negative values as 'section2'..... such way count " how many sections are there?".
PS: Each section may have more than 5 (may be 8 or 10 or even more) consecutive negative values rows. Just need to make sure at least 5 consecutive rows are negative. Thank you.
Sample data is attached. Here, first column is the number (in my case ions), second is Vx, third Vy and fourth Vz. I want to check if the Vy reverses or not (the third column)
Azzi Abdelmalek il 3 Mag 2016
a=rand(100,3)-0.6 % Example
Roger Stafford il 4 Mag 2016
Let x be the third column of your data matrix.
f = find(diff([false;x<0;false])~=0);
ns = length(find(f(2:2:end)-f(1:2:end-1)>=5)); % Total number of sections
Note: This is a solution to your originally stated problem. In the revised version, as given in your comment, I can’t tell whether, say, several 1’s in the first column separated by another value and then returning later to 1’s would count as “consecutive” 1’s if all the 1’s were accompanied by negative values in the third column. I think you need to resolve that uncertainty and open up a new ‘Answers’ question for that.