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

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

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

A = [0;1;0;1;1;1;1;0;0;0;1;0]
Z2O = diff(A);
trans = find(Z2O==1);
this will result in trans =[1;3;10] and as you can see the answer trans is the location of each 0 to 1 in A.
Ok, Joseph.
It shows all the columns that I had the transition == 1.
Now i would like to print the first and the second column in this exaclty moment, because the first column means time and i would like to know the instants that the transition==1 happens. Could you help me? Im reading a sensor sign.
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
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!