在MATLAB中计算0-1数据中连续1s的出现 [英] Count the occurrence of consecutive 1s in 0-1 data in MATLAB

查看:349
本文介绍了在MATLAB中计算0-1数据中连续1s的出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组1和0.如何计算连续1的最大数量?

I have a set of 1s and 0s. How do I count the maximum number of consecutive 1s?

(例如,x = [ 1 1 0 0 1 1 0 0 0 1 0 0 1 1 1 ....]).这里的答案是3,因为1连续出现的最大次数是3.

(For example, x = [ 1 1 0 0 1 1 0 0 0 1 0 0 1 1 1 ....]). Here the answer is 3 because the maximum number of times 1 occurs consecutively is 3.

我正在查看一些搜索和计数内置函数,但是没有成功.

I was looking at some search and count inbuilt function, however I have not been successful.

推荐答案

尝试一下:

max( diff( [0 (find( ~ (x > 0) ) ) numel(x) + 1] ) - 1)

这篇关于在MATLAB中计算0-1数据中连续1s的出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆