(HELP) Algorithm that notice the moment that a vector with 2 columns varies

1 view (last 30 days)
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

Accepted Answer

Joseph Cheng
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
Michel
Michel on 9 Jul 2014
i know how to disp each one like disp(X(1894,:)) for the first transition but im trying a algorithm that show for every transition
Joseph Cheng
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.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!