Detect change between two values in an array
Show older comments
Is there any function in Matlab that allows you to read through a column in an array and see if a previous value is the same as a current value? I know there is the "detect change" function block in Simulink and was looking to do something similar with code, however.
Accepted Answer
More Answers (1)
Image Analyst
on 1 Oct 2013
Try this:
x=[ 0 0 4 5 7 3 3 87 2 5 1 1]
changedIndexes = diff(x)~=0
6 Comments
Muneer
on 3 Oct 2013
Gervasio Batista
on 1 Dec 2017
Could you extend this to an cell array, please? Thank you!
Brandon Leonard
on 30 Apr 2018
Could you extend this to an cell array, please? Thank you!
Image Analyst
on 1 May 2018
Use cell2mat() on your cell array first.
Nikolaos Vasilas
on 25 Aug 2018
what if the table has nan values?
Image Analyst
on 25 Aug 2018
Table variables can be nan, just like double variables. Actually a column of a table has to be a predetermined type, like double, char, int32, or whatever. So if a column is double, then it's allowable for a row in that double column to have a value of "nan".
Categories
Find more on Cell Arrays 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!