在matlab中比较两个相同长度的不同向量
我有两个矩阵 A 和 B。A 是一个长度为 1000X1 的数组,由 0 和 1 组成,B 也具有相同的大小。现在 B 是一个以 A 作为输入执行扫描操作的函数的输出。扫描只不过是在 A 中的 1 位置添加零。因此,B 的值与 A 类似,只是其中一些 1 被替换为 0。现在我的任务是填充 B 中的那些 0 值,这些值在扫描操作后被随机二进制值替换。我是在这个很棒的网站的用户的帮助下完成的。相同的代码在这里
idx=strfind(B,[0 0 0 0]);
n=dec2bin(randi([0 15],[numel(idx) 1]),4) - '0';
idx=bsxfun(@plus, idx', (0:3));
xx = B;
xx(idx(:)) = n(:);
现在这个函数还将替换 A 中已经存在的零。我只想替换那些从 1 更改为 0 的零,而不替换 A 中已经为零的那些 0。任何帮助我们将非常感激。
I have two matrix A and B. A is a array of length 1000X1 consisting of 0's and 1's and B is also of the same size. Now B is the output of a function that performs a sweep operation taking A as input. Sweep is nothing but addition of zeros in the place of 1 in A. so values of B is similar to A except some of the 1's are replaced by 0's. Now my task is to fill those 0 values in B which was replaced after sweep operation by random binary values.I have done this with help of a user form this awesome website. And the code for the same is here
idx=strfind(B,[0 0 0 0]);
n=dec2bin(randi([0 15],[numel(idx) 1]),4) - '0';
idx=bsxfun(@plus, idx', (0:3));
xx = B;
xx(idx(:)) = n(:);
Now this function will also replace the zeros which was already present in A. I want to replace only those zeros which were changed from 1's to 0's and not those 0's which were already zeros in A. Any help would be very much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会这样做:
I would do: