我需要使用矢量化方法从矩阵中识别非交替值
因此,我在 MATLAB 中有一个一维值矩阵,其中包含值 11 或 12。
例如 n=[11,12,11,12,12,12,11,11];
我想根据以下规则挑选值:
任何 11 值前面都必须有 12
任何 12 值后面都必须跟着一个 11
输出的格式并不重要。突出显示不符合上述规则的数组(例如 n1=[0,1,1,0,0,1,1,0];
)就可以解决问题。
我怎样才能以矢量化的方式做到这一点?
So, I've got a 1D matrix of values in MATLAB that will contain the value either 11 or 12.
For example n=[11,12,11,12,12,12,11,11];
I want to pick out values based on the following rules:
Any value of 11 must be preceeded by a 12
Any value of 12 must be followed by an 11
The format of the output isn't important. An array that highlights which don't conform to the above rules such as n1=[0,1,1,0,0,1,1,0];
would do the trick.
How can I do this in a vectorized way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这段代码应该可以工作:
基本上我们正在查看前面的数字大于后面的数字 1 的序列。
This code should work:
Basically we are looking at the sequence with preceding number is greater than following by 1.