分析序列matlab
我正在尝试编写一个简短的 matlab 函数,它将接收一个向量,并返回最长 1 序列的第一个元素的索引(我可以假设该序列由 1 和 0 组成)。例如:
<块引用>IndexLargeSeq([110001111100000000001111111111110000000000000000000000000000000])
将返回 21 - 这是最长 1 序列中第一个 1 的索引。
谢谢你
爱丽儿
I am trying to write a short matlab function that will recieve a vector and will return me the index of the first element of the longest sequence of 1s (I can assume that the sequence consists of 1s and 0s). for example:
IndexLargeSeq([110001111100000000001111111111110000000000000000000000000000000])
will return 21 - which is the index of the first 1 of the longest sequence of 1s.
thank you
ariel
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
就是这样:
idx
是您要查找的值(索引),maxSeq
是这个 1 序列的长度。A
必须是行向量。如果您想了解数据集是如何累积的(命令
B = ...
),请查看此处:如何累积数据集?。There you go:
idx
than is the value (the index) you are looking for,maxSeq
is the length of this sewuence of 1s.A
has to be a row-vector.If you want to understand how the datasets are accumulated (the command
B = ...
), look here: How to accumulate data-sets?.这是测量 0 索引之间距离的另一个选项。该代码考虑了根本没有 1(返回空向量)或存在多个具有最长长度的序列的情况。
x
是输入行向量。编辑:如果
x
可以是行向量或列向量,您可以将第一行更改为在这种情况下,输出将是列向量。
Here is another option measuring distances between indices of 0s. The code takes into account situations if there are no 1s at all (returns empty vector), or if there are multiple sequences with the longest length.
x
is an input row vector.EDIT: If
x
can be either row or column vector, you can change the first line toThe output will be a column vector in this case.