(HELP) Algorithm that notice the moment that a vector with 2 columns varies
1 view (last 30 days)
Show older comments
Hello guys,
Im very new using matlab and programation.
I have a vector X with 200000 lines and 2 columns, the second column has only 0 and 1 (binary). I would like to make a algorithm that notice me everytime that the second column goes from 0 to 1.
Can someone help?
Thank you
0 Comments
Accepted Answer
Joseph Cheng
on 9 Jul 2014
you can use the diff() function on the second column. then use the find() function to see which items are 1 (the 0 to 1 transition), 0 (no transition 1 to 1 and 0 to 0, and -1 (1 to 0 transitions).
example:
transition = diff(X(:,2)); %get the diff of second column for all rows.
ZeroToOne = find(transition == 1);
the ZeroToOne variable will the the indexes where there is the 0 to 1 transition (located on the 0).
5 Comments
Joseph Cheng
on 9 Jul 2014
you can basically do that as well. since you have a list of which rows have the transition ==1 you can go disp(X(transition,:)) which is displaying the variable X for the rows specified in transition, and all columns.
or instead of displaying (which may be thousands of lines) why not store the time? transTimeData = X(transition,:); %save the transition time and data.
More Answers (0)
See Also
Categories
Find more on Call Python from MATLAB 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!