Detect change between two values in an array
67 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
Sean de Wolski
2013-10-1
编辑:Sean de Wolski
2013-10-1
x = [1 1 2 3 4 4 5 6 6 6 6 7];
diff(x)==0 %?
4 个评论
Brandon Leonard
2018-4-16
编辑:Brandon Leonard
2018-4-16
Sean de Wolski would this same approach work for two values from data collected (e.g. day = 1; night = 2) to locate where this change occurs in continuous data if data was stored in a timeseries? Could it be logged as a event(e.g. tsdata.event.EventData = logical(diff(x)) somehow?
更多回答(1 个)
Image Analyst
2013-10-1
Try this:
x=[ 0 0 4 5 7 3 3 87 2 5 1 1]
changedIndexes = diff(x)~=0
6 个评论
Image Analyst
2018-8-25
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".
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!