需要分析一组包含0和正整数的向量
我正在使用 Matlab,并且有一个 1x200 的数字向量。
我需要按照以下规则为这组数字分配一个“分数”:
- 如果有 2 个或 3 个或 4 个连续正数,则 0.5 分
- 如果有 5 个或更多连续正数,则 1.0 分
- 如果没有t 任何连续的正数,例如:0 0 0 6 0 0,则为 0.0 点。 (忽略它,将正数视为零)
- 如果一串正整数中间只有一个零,则忽略该零(将其视为正整数)
- 如果有两个或多个连续的零,这打破了连续正数的运行。
示例: 30 43 54 0 0 0 41 54 14 10 1 0 0 0 0 32 41 98 12 0 0 0 (总共 2.0 分)
最后,应该有一个分数统计。
对于此类问题有什么有用的函数吗?
I am using Matlab, and I have a 1x200 vector of numbers.
I need to assign a "score" to the set of numbers by following these rules:
- If there are 2 or 3 or 4 consecutive positive numbers, then 0.5 points
- If there are five or more consecutive positive numbers, then 1.0 points
- If there isn't any consecutive positive number, for example: 0 0 0 6 0 0, then 0.0 point. (ignore it, consider that positive number as zero)
- If there is only one zero in the middle of a run of positive integers, then ignore that zero (consider it as a positive integer)
- If there are two or more consecutive zeroes, that breaks the run of consecutive positive numbers.
Example: 30 43 54 0 0 0 41 54 14 10 1 0 0 0 0 32 41 98 12 0 0 0 (2.0 points total)
At the end, there should be a tally of the points.
Are there any useful functions for this type of problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是基于我对这个问题的理解,正如我在上面的问题中所指出的。我已经“取消抑制”所有输出,因此您可以看到发生了什么。
This is based on my understanding of the question, as noted in my question above. I've "unsuppressed" all output, so you can see what's going on.
怎么样:
请注意,我还没有运行过这个,所以可能会有错误。
How about:
Note that I haven't run this, so there may be errors.